cURL / Mailing Lists / curl-library / Single Mail

curl-library

Memory Leek?

From: Yanick Pelletier <ypelletier_at_copernic.com>
Date: Tue, 16 Oct 2001 13:36:06 -0400

I think that i have found a potential memory leek in the function
Curl_perform().
The code look like this:

*1 struct connectdata *conn=NULL;
          bool port=TRUE;
          char *newurl = NULL;

          if(!data->change.url)
            return CURLE_URL_MALFORMAT;

          data->set.followlocation=0;
          data->state.this_is_a_follow = FALSE;

          Curl_initinfo(data);

          Curl_pgrsStartNow(data);

          do {
            Curl_pgrsTime(data, TIMER_STARTSINGLE);
*2 res = Curl_connect(data, &conn, port);
            if(res == CURLE_OK) {
              res = Curl_do(conn);
              if(res == CURLE_OK) {
                if(conn->protocol&PROT_FTPS)
                  conn->ssl.use = FALSE;
                res = Transfer(conn);
                if(conn->protocol&PROT_FTPS)
                  conn->ssl.use = TRUE;

*3 if(res == CURLE_OK) {
                  newurl = conn->newurl?strdup(conn->newurl):NULL;

*4 res = Curl_done(conn);
                }
              }
        ...

The remaining of the function do nothing of interest.
(the * indicate the line of interest)

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!

Can you fix it in your next release>
Does always calling Curl_done() is an acceptable solution?

Thanks
Yanick
Received on 2001-10-16