Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 8 Sep 2005 15:01:53 +0200
From:      "Cole" <cole@opteqint.net>
To:        <freebsd-hackers@freebsd.org>
Subject:   Memory Leak && Free Problem
Message-ID:  <20050908125901.BDFB943D46@mx1.FreeBSD.org>

next in thread | raw e-mail | index | archive | help
Hi

I have the netapp code they release for icap server. Ive ported it to FreeBSD. And I have found
there is a memory leak in the code itself. Ive tried contacting netapp directly, but no reply.

Their code can be found at : http://www.i-cap.org/spec/icap-server10.tar.gz

Ive been trying to fix the memory leak, and I think i've found the problem, but when I try to free
the buffer, I get this error.
icap_srv in free(): warning: page is already free

In the function : 
api_modify_respmod(const char* icap_hdr,
                   const char* client_hdr,
                   const char* origin_resp_hdr,
                   const char* origin_resp_body,
                   int origin_resp_body_len)

We have this section of code:
1.   new_body = api_filter(origin_resp_body,origin_resp_body_len);
2.   origin_resp_body_len = new_body->length;
3.   origin_resp_body = new_body->data;

I figure that the memory leak is occuring with origin_resp_body being assigned to the new_body
buffer. But if I try to insert a free(origin_resp_body) between line 1. and 2. I get the error
"icap_srv in free(): warning: page is already free" when running the program, or either the error
"free(): warning: junk pointer, too high to make sense"

I was wondering if there is somethign missing here. Ive checked the function api_filter, and it
doesnt do anything in regards to free'ing origin_resp_body, and ive also checked the data in the
buffer origin_resp_body before and after the function call to api_filter, and both values are
exactly the same.

The entire program is threaded, and I suppose it could be possible there is some kind of thread
problem occuring here? 

Ive also run the program through valgrind, to try and find the other memory leaks, but that one
seems the most obvious when going through the code.

Anyway, I would just like to know if anyone has any ideas or suggestions, or to point out that im a
complete moron and missing something, anything would be welcome.

Regards
/Cole




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050908125901.BDFB943D46>