cURL / Mailing Lists / curl-users / Single Mail

curl-users

Memory Leak in cURL main.c

From: Song Ma <songmash_at_gmail.com>
Date: Tue, 10 Jul 2007 14:53:41 +0800

Hi Daniel,

I found there is one major memory leak caused by the following case. Let's
call it "test5000". The case is trying to upload a file which is not existed
in designated directory. You can refer to the valgrind check log in the
attached files. The log was generated with "./runtests.pl -k 5000".
"log/ftpserver5000.cmd" is never existed.

<testcase>
# Client-side
<client>
<server>
ftp
</server>
 <name>
FTP resume upload but denied access to remote file
 </name>
 <command>
ftp://%HOSTIP:%FTPPORT/5000 -T log/ftpserver5000.cmd -C -
</command>
</client>

# Verify data after the test has been "shot"
<verify>
<errorcode>
26
</errorcode>
</verify>
</testcase>

I've made the patch based on snapshot version "curl-7.16.4-20070709". The
root cause for the leaky is because cURL does not release the allocated
resource before one exceptional return.
I also attached the valgrind check log after my fix for your reference.

Best Regards,
Song Ma
--- main.c.orig 2007-07-10 14:43:07.000000000 +0800
+++ main.c 2007-07-09 17:58:59.000000000 +0800
@@ -4009,6 +4009,32 @@
             helpf("Can't open '%s'!\n", uploadfile);
             if(infd)
               fclose(infd);
+
+ dumpeasycode(config);
+ clean_getout(config);
+ curl_easy_cleanup(curl);
+
+ if(inglob) {
+ glob_cleanup(inglob);
+ inglob = NULL;
+ }
+
+ if(urls)
+ /* cleanup memory used for URL globbing patterns */
+ glob_cleanup(urls);
+
+ if(outfile)
+ free(outfile);
+
+ if(outfiles)
+ free(outfiles);
+
+ if(uploadfile)
+ free(uploadfile);
+
+ if(url)
+ free(url);
+
             return CURLE_READ_ERROR;
           }
           infdfopen=TRUE;

Received on 2007-07-10