cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Memory leak using write_cb

From: Dan Fandrich <dan_at_coneharvesters.com>
Date: Wed, 13 Sep 2006 10:12:53 -0700

On Wed, Sep 13, 2006 at 12:24:37PM -0400, jessica rearick wrote:
> I am using the following curl calls to receive data back from an HTTP POST.
> CCERequestData *memory;
> (curl, CURLOPT_WRITEFUNCTION, write_cb)
> (curl, CURLOPT_WRITEDATA, memory)
>
> My write_cb function looks like this below(a piece of it)
> Int realsize = size * nmemb;
> CCERequestData *memory = data;
> (3)memory->data = (char*) realloc(memory->data, memory->len + realsize + 1);
>
> Everything works fine, but I am recieving a memory leak on line #3. I have
> tried to free(memory) within the write_cb method, but then I dont get my
> response back correctly. Also note, that I do free(memory) on the
> CCERequestData structure. Any suggestions please!

If you're freeing the memory you just realloc'ed within the callback, then
where is your data stored? You only need to free() 'memory' if you malloc'ed
it beforehand. Nowhere in the code snippet you gave do you show that you
alloced any heap to be stored at 'memory', nor do you show that you alloced
any heap to be used as the initial memory block in 'memory->data'. Nor do you
show where you free 'memory->data' after your transfer is complete.

It's hard to guess at what your code is actually doing. Why not show
us the actual code?

>>> Dan

-- 
http://www.MoveAnnouncer.com              The web change of address service
          Let webmasters know that your web site has moved
Received on 2006-09-13