cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: deallocation of MemoryStruct in callback

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Mon, 10 Mar 2003 17:58:47 +0100 (CET)

On Fri, 7 Mar 2003, Jami Amore wrote:

> I've written a program that uses part of the getinmemory.c example from the
> libcurl website (I've pasted that example in below). I'm curious as to why
> there isn't a free() anywhere the corresponds to the realloc() in the
> WriteMemoryCallback. Is the deallocation of that memory taken care of by
> curl_easy_cleanup()?

Oh no. The struct and the allocation is all done in the callbacks and the
library of course has no clue or knowledge of what's going on. The
allocation, the free, the realloc and everything is dealt with in code you
write.

Yes, you should free the data when you're done with it. Or as the comment in
the code says:

> 72 /*
> 73 * Now, our chunk.memory points to a memory block
> that is chunk.size
> 74 * bytes big and contains the remote file.
> 75 *
> 76 * Do something nice with it!
> 77 */

-- 
 Daniel Stenberg -- curl, cURL, Curl, CURL. Groks URLs.
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
Received on 2003-03-10