cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Memory Leek?

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Wed, 17 Oct 2001 00:14:52 +0200 (MET DST)

On Tue, 16 Oct 2001, Yanick Pelletier wrote:

> I think that i have found a potential memory leek in the function
> Curl_perform().

Did you see memory usage actually increase? What OS are you using? We've
already removed a memory leak since 7.9...

> *1 struct connectdata *conn=NULL;
> Curl_pgrsTime(data, TIMER_STARTSINGLE);
> *2 res = Curl_connect(data, &conn, port);
> if(res == CURLE_OK) {
>
> *3 if(res == CURLE_OK) {
> newurl = conn->newurl?strdup(conn->newurl):NULL;
>
> *4 res = Curl_done(conn);
> }

> If we look at the 1st line (*1) we have a pointer on the connection data.
> The data at which we point is allocate in the Curl_Connect() function
> (*2). After the call to Transfer() whe check if the transfert was done
> correctly (*3) is so we call Curl_done() (*4), function into which we
> free all the stuff allocated in *2. The leek can occur when the
> transfert doesn't work correctly, in this case we doesn't free the
> allocated stuff!

Then also note these little details:

 o In the function Curl_connect(), the newly created connection is stored in
   the connection "cache".
 o When leaving the function Curl_perform() you describe above with an error
   code, the connection is still left in the cache.
 o Later, when curl_easy_cleanup() is called, the connection cache is cleaned.

AFAICS, there is indeed a memory leak possibility, which comes from the fact
that if Curl_done() isn't called, we never end up calling the proper
protocol-specific done() function.

Can you produce with a repeatable test case when this happens?

> Can you fix it in your next release?

I certainly think so. I need to think through first what happens/should
happen with the existing connection. I think it could be left in the cache,
as a mere transfer error doesn't have to imply that there's a connection
problem, but perhaps we might need to add a way to control that...

> Does always calling Curl_done() is an acceptable solution?

Hm, well it should be OK to do if Curl_do() has been called. It shouldn't be
done if Curl_connect() fails.

-- 
    Daniel Stenberg -- curl groks URLs -- http://curl.haxx.se/
Received on 2001-10-17