curl-library
Patch for FTP memory leak in v7.10.6
Date: Fri, 08 Aug 2003 11:59:03 +0200
Hello Curl-Fans,
I am using the curl library (v. 7.10.6) in a slightly different way than
most,
as I'm setting up a connection to one host and transmitting (uploading)
several thousand files via FTP:
------------------ Example code -------------------------------------
void f(void)
{
CURL *curl;
FILE *ifp;
int i;
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
/* Yes, we're uploading... */
curl_easy_setopt(curl, CURLOPT_UPLOAD, TRUE);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, TRUE);
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, TRUE);
curl_easy_setopt(curl, CURLOPT_DNS_USE_GLOBAL_CACHE, TRUE);
curl_easy_setopt(curl, CURLOPT_DNS_CACHE_TIMEOUT, 60 * 60);
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, CurlErrorBuffer);
curl_easy_setopt(curl, CURLOPT_FTP_USE_EPRT, FALSE);
curl_easy_setopt(curl, CURLOPT_FTP_USE_EPSV, FALSE);
curl_easy_setopt(curl, CURLOPT_FTPPORT, ftpport);
curl_easy_setopt(curl, CURLOPT_USERPWD, usrpwd);
for (i = 0; i < 5000; i++) {
ifp = fopen(filename[i], "r");
sprintf(remote_url, "ftp://desthost:1005/file%d", i);
curl_easy_setopt(curl, CURLOPT_URL, remote_url);
curl_easy_setopt(curl, CURLOPT_INFILE, ifp);
curl_easy_setopt(curl, CURLOPT_TRANSFERTEXT, !isbinary);
curl_easy_setopt(curl, CURLOPT_CRLF, !isbinary);
curl_easy_perform(curl);
fclose(ifp);
}
curl_easy_cleanup(curl);
curl_global_cleanup();
}
-------------------------------------------------------------------------
This reveals a memory leak in the ftp protocol handler:
--------------------- Patch against curl 7.10.6
--------------------------------
*** curl-7.10.6/lib/ftp.c 2003-08-08 11:32:30.000000000 +0200
--- curl-fixed/lib/ftp.c 2003-08-08 11:32:36.000000000 +0200
***************
*** 2141,2146 ****
--- 2141,2151 ----
/* we skip empty path components, like "x//y" since the FTP
command CWD
requires a parameter and a non-existant parameter a) doesn't
work on
many servers and b) has no effect on the others. */
+
+ /* Memory leak fix by krp_at_dannet.dk 030808 */
+ if (ftp->dirs[path_part])
+ free(ftp->dirs[path_part]);
+
ftp->dirs[path_part] = curl_unescape(cur_pos - absolute_dir,
slash_pos - cur_pos +
absolute_dir);
***************
*** 2173,2178 ****
--- 2178,2191 ----
}
}
+ /* Memory leak fix by krp_at_dannet.dk 030808 */
+ if (ftp->dirs[path_part]) {
+ free(ftp->dirs[path_part]);
+ ftp->dirs[path_part] = NULL;
+ }
+ if (ftp->file)
+ free(ftp->file);
+
ftp->file = cur_pos; /* the rest is the file name */
--------------------------- End of patch
----------------------------------------
The leak is not very big, but since my program is runnning non-stop for
month,
it will become a problem.
Regards
Kim R. Pedersen
-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
Received on 2003-08-08