cURL / Mailing Lists / curl-library / Single Mail

curl-library

Memory leak when using CURLOPT_USERPWD and making multiple reques ts

From: Becker, Dan <dbecker_at_3eti.com>
Date: Tue, 26 Nov 2002 09:40:59 -0500

To all,

I had a memory leak when using CURLOPT_USERPWD and making multiple requests
with curl_easy_perform().

I tracked the memory leak to this area of code:

http.c:

CURLcode Curl_http_connect(struct connectdata *conn)
{
....
   data->state.auth_host = strdup(conn->hostname);
....

It seems to me that when you make multiple requests, the strdup on repeated
requests leaks memory. Curl_close() which is called from
curl_easy_cleanup() does free this memory; however, I am making multiple
calls to curl_easy_perform() before I call curl_easy_cleanup().

I added the following lines of code:

    if (data->state.auth_host) {
       /* Free to avoid leaking memory on multiple requests*/
       free(data->state.auth_host);
    }
   data->state.auth_host = strdup(conn->hostname);

which cleaned up my leak.

Does this change make sense?

Dan Becker
email:dbecker_at_3eti.com

-------------------------------------------------------
This SF.net email is sponsored by: Get the new Palm Tungsten T
handheld. Power & Color in a compact size!
http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0002en
Received on 2002-11-26