cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Memory leak in curl

From: Daniel Stenberg <daniel-curl_at_haxx.se>
Date: Fri, 20 Aug 2004 12:39:07 +0200 (CEST)

On Fri, 20 Aug 2004, Rupesh wrote:

(This reply is CC'ed to the libcurl mailing list, I suggest you use that
instead since you're talking libcurl stuff here.)

> I am using curl library version 7.10.5 for HTTP1.1 client functionality.

That is a rather old version by now. I suggest you upgrade.

> I am receiving data received from server in callback function. After I
> receive the data I am trying to free it using curl_free fuction but it gives
> me core dump. If I don't delete it I am getting memory leak for that data.

You get called with a pointer to data that you must not (attempt to) free.

> size_t ReadReply(void *buffer, size_t size, size_t
> nmemb, void *userp)
> {
> m_strReply = new char[size*nmemb +1 ];
> memset(m_strReply,0,size*nmemb);
> memcpy(m_strReply,buffer,size*nmemb);
> return size*nmemb;
> }

Of course this leaks memory since you do a 'new' and never delete the memory
again. This isn't libcurl's fault.

> How can I delete memory allocated for first parameter in this function or
> curl do it for me?

Again: you just don't. When you call curl_easy_cleanup() later on, libcurl
frees all internal memory it has allocated that is associated with the given
curl handle.

> I tried free_curl(buffer) it is giving me core dump.

I'm not surprised.

-- 
      Daniel Stenberg -- http://curl.haxx.se -- http://daniel.haxx.se
       Dedicated custom curl help for hire: http://haxx.se/curl.html
Received on 2004-08-20