memory leak cleanup campaign
This commit is contained in:
parent
7f77a061dd
commit
868488b518
@ -620,7 +620,7 @@ CURLcode curl_transfer(CURL *curl)
|
|||||||
{
|
{
|
||||||
CURLcode res;
|
CURLcode res;
|
||||||
struct UrlData *data = curl;
|
struct UrlData *data = curl;
|
||||||
struct connectdata *c_connect;
|
struct connectdata *c_connect=NULL;
|
||||||
|
|
||||||
pgrsStartNow(data);
|
pgrsStartNow(data);
|
||||||
|
|
||||||
|
@ -390,6 +390,7 @@ CURLcode http(struct connectdata *conn)
|
|||||||
|
|
||||||
if(co) {
|
if(co) {
|
||||||
int count=0;
|
int count=0;
|
||||||
|
struct Cookie *store=co;
|
||||||
/* now loop through all cookies that matched */
|
/* now loop through all cookies that matched */
|
||||||
while(co) {
|
while(co) {
|
||||||
if(co->value && strlen(co->value)) {
|
if(co->value && strlen(co->value)) {
|
||||||
@ -405,7 +406,7 @@ CURLcode http(struct connectdata *conn)
|
|||||||
if(count) {
|
if(count) {
|
||||||
add_buffer(req_buffer, "\r\n", 2);
|
add_buffer(req_buffer, "\r\n", 2);
|
||||||
}
|
}
|
||||||
cookie_freelist(co); /* free the cookie list */
|
cookie_freelist(store); /* free the cookie list */
|
||||||
co=NULL;
|
co=NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
65
lib/url.c
65
lib/url.c
@ -685,26 +685,7 @@ CURLcode curl_disconnect(CURLconnect *c_connect)
|
|||||||
return CURLE_OK;
|
return CURLE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static CURLcode _connect(CURL *curl, CURLconnect **in_connect)
|
||||||
/*
|
|
||||||
* NAME curl_connect()
|
|
||||||
*
|
|
||||||
* DESCRIPTION
|
|
||||||
*
|
|
||||||
* Connects to the peer server and performs the initial setup. This function
|
|
||||||
* writes a connect handle to its second argument that is a unique handle for
|
|
||||||
* this connect. This allows multiple connects from the same handle returned
|
|
||||||
* by curl_open().
|
|
||||||
*
|
|
||||||
* EXAMPLE
|
|
||||||
*
|
|
||||||
* CURLCode result;
|
|
||||||
* CURL curl;
|
|
||||||
* CURLconnect connect;
|
|
||||||
* result = curl_connect(curl, &connect);
|
|
||||||
*/
|
|
||||||
|
|
||||||
CURLcode curl_connect(CURL *curl, CURLconnect **in_connect)
|
|
||||||
{
|
{
|
||||||
char *tmp;
|
char *tmp;
|
||||||
char *buf;
|
char *buf;
|
||||||
@ -1537,6 +1518,50 @@ CURLcode curl_connect(CURL *curl, CURLconnect **in_connect)
|
|||||||
return CURLE_OK;
|
return CURLE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CURLcode curl_connect(CURL *curl, CURLconnect **in_connect)
|
||||||
|
{
|
||||||
|
CURLcode code;
|
||||||
|
struct connectdata *conn;
|
||||||
|
|
||||||
|
/* call the stuff that needs to be called */
|
||||||
|
code = _connect(curl, in_connect);
|
||||||
|
|
||||||
|
if(CURLE_OK != code) {
|
||||||
|
/* We're not allowed to return failure with memory left allocated
|
||||||
|
in the connectdata struct, free those here */
|
||||||
|
conn = (struct connectdata *)*in_connect;
|
||||||
|
if(conn) {
|
||||||
|
if(conn->hostent_buf)
|
||||||
|
free(conn->hostent_buf);
|
||||||
|
free(conn);
|
||||||
|
*in_connect=NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* NAME curl_connect()
|
||||||
|
*
|
||||||
|
* DESCRIPTION
|
||||||
|
*
|
||||||
|
* Connects to the peer server and performs the initial setup. This function
|
||||||
|
* writes a connect handle to its second argument that is a unique handle for
|
||||||
|
* this connect. This allows multiple connects from the same handle returned
|
||||||
|
* by curl_open().
|
||||||
|
*
|
||||||
|
* EXAMPLE
|
||||||
|
*
|
||||||
|
* CURLCode result;
|
||||||
|
* CURL curl;
|
||||||
|
* CURLconnect connect;
|
||||||
|
* result = curl_connect(curl, &connect);
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CURLcode curl_done(CURLconnect *c_connect)
|
CURLcode curl_done(CURLconnect *c_connect)
|
||||||
{
|
{
|
||||||
struct connectdata *conn = c_connect;
|
struct connectdata *conn = c_connect;
|
||||||
|
100
src/main.c
100
src/main.c
@ -365,6 +365,7 @@ static char *my_get_token(const char *line);
|
|||||||
static void GetStr(char **string,
|
static void GetStr(char **string,
|
||||||
char *value)
|
char *value)
|
||||||
{
|
{
|
||||||
|
fprintf(stderr, "called\n");
|
||||||
if(*string)
|
if(*string)
|
||||||
free(*string);
|
free(*string);
|
||||||
if(value && *value)
|
if(value && *value)
|
||||||
@ -1278,6 +1279,8 @@ int main(int argc, char *argv[])
|
|||||||
int infilesize=-1; /* -1 means unknown */
|
int infilesize=-1; /* -1 means unknown */
|
||||||
bool stillflags=TRUE;
|
bool stillflags=TRUE;
|
||||||
|
|
||||||
|
bool allocuseragent=FALSE;
|
||||||
|
|
||||||
CURL *curl;
|
CURL *curl;
|
||||||
int res;
|
int res;
|
||||||
int i;
|
int i;
|
||||||
@ -1388,6 +1391,8 @@ int main(int argc, char *argv[])
|
|||||||
CURL_NAME "/" CURL_VERSION " (" OS ") " "%s", curl_version());
|
CURL_NAME "/" CURL_VERSION " (" OS ") " "%s", curl_version());
|
||||||
config.useragent= useragent;
|
config.useragent= useragent;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
allocuseragent = TRUE;
|
||||||
#if 0
|
#if 0
|
||||||
fprintf(stderr, "URL: %s PROXY: %s\n", url, config.proxy?config.proxy:"none");
|
fprintf(stderr, "URL: %s PROXY: %s\n", url, config.proxy?config.proxy:"none");
|
||||||
#endif
|
#endif
|
||||||
@ -1398,7 +1403,9 @@ int main(int argc, char *argv[])
|
|||||||
if(res != CURLE_OK)
|
if(res != CURLE_OK)
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
outfiles = config.outfile; /* save outfile pattern befor expansion */
|
/* save outfile pattern befor expansion */
|
||||||
|
outfiles = strdup(config.outfile);
|
||||||
|
|
||||||
if (!outfiles && !config.remotefile && urlnum > 1) {
|
if (!outfiles && !config.remotefile && urlnum > 1) {
|
||||||
#ifdef CURL_SEPARATORS
|
#ifdef CURL_SEPARATORS
|
||||||
/* multiple files extracted to stdout, insert separators! */
|
/* multiple files extracted to stdout, insert separators! */
|
||||||
@ -1412,15 +1419,10 @@ int main(int argc, char *argv[])
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
for (i = 0; (url = next_url(urls)); ++i) {
|
for (i = 0; (url = next_url(urls)); ++i) {
|
||||||
if (outfiles)
|
if (outfiles) {
|
||||||
config.outfile = strdup(outfiles);
|
free(config.outfile);
|
||||||
|
config.outfile = outfiles;
|
||||||
#if 0
|
|
||||||
if(config.outfile && config.infile) {
|
|
||||||
helpf("you can't both upload and download!\n");
|
|
||||||
return CURLE_FAILED_INIT;
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
if (config.outfile || config.remotefile) {
|
if (config.outfile || config.remotefile) {
|
||||||
/*
|
/*
|
||||||
@ -1428,21 +1430,25 @@ int main(int argc, char *argv[])
|
|||||||
* decided we want to use the remote file name.
|
* decided we want to use the remote file name.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if(config.remotefile) {
|
if(!config.outfile && config.remotefile) {
|
||||||
/* Find and get the remote file name */
|
/* Find and get the remote file name */
|
||||||
config.outfile=strstr(url, "://");
|
config.outfile=strstr(url, "://");
|
||||||
if(config.outfile)
|
if(config.outfile)
|
||||||
config.outfile+=3;
|
config.outfile+=3;
|
||||||
else
|
else
|
||||||
config.outfile=url;
|
config.outfile=url;
|
||||||
config.outfile = strrchr(config.outfile, '/');
|
config.outfile = strdup(strrchr(config.outfile, '/'));
|
||||||
if(!config.outfile || !strlen(++config.outfile)) {
|
if(!config.outfile || !strlen(++config.outfile)) {
|
||||||
helpf("Remote file name has no length!\n");
|
helpf("Remote file name has no length!\n");
|
||||||
return CURLE_WRITE_ERROR;
|
return CURLE_WRITE_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else /* fill '#1' ... '#9' terms from URL pattern */
|
else {
|
||||||
|
/* fill '#1' ... '#9' terms from URL pattern */
|
||||||
|
char *outfile = config.outfile;
|
||||||
config.outfile = match_url(config.outfile, *urls);
|
config.outfile = match_url(config.outfile, *urls);
|
||||||
|
free(outfile);
|
||||||
|
}
|
||||||
|
|
||||||
if((0 == config.resume_from) && config.use_resume) {
|
if((0 == config.resume_from) && config.use_resume) {
|
||||||
/* we're told to continue where we are now, then we get the size of the
|
/* we're told to continue where we are now, then we get the size of the
|
||||||
@ -1483,8 +1489,9 @@ int main(int argc, char *argv[])
|
|||||||
ptr=url;
|
ptr=url;
|
||||||
ptr = strrchr(ptr, '/');
|
ptr = strrchr(ptr, '/');
|
||||||
if(!ptr || !strlen(++ptr)) {
|
if(!ptr || !strlen(++ptr)) {
|
||||||
/* The URL has no file name part, add the local file name. In order
|
/* The URL has no file name part, add the local file name. In order to
|
||||||
to be able to do so, we have to create a new URL in another buffer.*/
|
be able to do so, we have to create a new URL in another buffer.*/
|
||||||
|
|
||||||
urlbuffer=(char *)malloc(strlen(url) + strlen(config.infile) + 3);
|
urlbuffer=(char *)malloc(strlen(url) + strlen(config.infile) + 3);
|
||||||
if(!urlbuffer) {
|
if(!urlbuffer) {
|
||||||
helpf("out of memory\n");
|
helpf("out of memory\n");
|
||||||
@ -1515,8 +1522,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
if(config.headerfile) {
|
if(config.headerfile) {
|
||||||
/* open file for output: */
|
/* open file for output: */
|
||||||
if(strcmp(config.headerfile,"-"))
|
if(strcmp(config.headerfile,"-")) {
|
||||||
{
|
|
||||||
heads.filename = config.headerfile;
|
heads.filename = config.headerfile;
|
||||||
headerfilep=NULL;
|
headerfilep=NULL;
|
||||||
}
|
}
|
||||||
@ -1527,13 +1533,14 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
if(outs.stream && isatty(fileno(outs.stream)) &&
|
if(outs.stream && isatty(fileno(outs.stream)) &&
|
||||||
!(config.conf&(CONF_UPLOAD|CONF_HTTPPOST)))
|
!(config.conf&(CONF_UPLOAD|CONF_HTTPPOST)))
|
||||||
/* we send the output to a tty and it isn't an upload operation, therefore
|
/* we send the output to a tty and it isn't an upload operation,
|
||||||
we switch off the progress meter */
|
therefore we switch off the progress meter */
|
||||||
config.conf |= CONF_NOPROGRESS;
|
config.conf |= CONF_NOPROGRESS;
|
||||||
|
|
||||||
|
|
||||||
if (urlnum > 1) {
|
if (urlnum > 1) {
|
||||||
fprintf(stderr, "\n[%d/%d]: %s --> %s\n", i+1, urlnum, url, config.outfile ? config.outfile : "<stdout>");
|
fprintf(stderr, "\n[%d/%d]: %s --> %s\n",
|
||||||
|
i+1, urlnum, url, config.outfile ? config.outfile : "<stdout>");
|
||||||
if (separator) {
|
if (separator) {
|
||||||
#ifdef CURL_SEPARATORS
|
#ifdef CURL_SEPARATORS
|
||||||
printf("%s%s\n", CURLseparator, url);
|
printf("%s%s\n", CURLseparator, url);
|
||||||
@ -1574,10 +1581,12 @@ int main(int argc, char *argv[])
|
|||||||
curl_easy_setopt(curl, CURLOPT_HEADER, config.conf&CONF_HEADER);
|
curl_easy_setopt(curl, CURLOPT_HEADER, config.conf&CONF_HEADER);
|
||||||
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, config.conf&CONF_NOPROGRESS);
|
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, config.conf&CONF_NOPROGRESS);
|
||||||
curl_easy_setopt(curl, CURLOPT_NOBODY, config.conf&CONF_NOBODY);
|
curl_easy_setopt(curl, CURLOPT_NOBODY, config.conf&CONF_NOBODY);
|
||||||
curl_easy_setopt(curl, CURLOPT_FAILONERROR, config.conf&CONF_FAILONERROR);
|
curl_easy_setopt(curl, CURLOPT_FAILONERROR,
|
||||||
|
config.conf&CONF_FAILONERROR);
|
||||||
curl_easy_setopt(curl, CURLOPT_UPLOAD, config.conf&CONF_UPLOAD);
|
curl_easy_setopt(curl, CURLOPT_UPLOAD, config.conf&CONF_UPLOAD);
|
||||||
curl_easy_setopt(curl, CURLOPT_POST, config.conf&CONF_POST);
|
curl_easy_setopt(curl, CURLOPT_POST, config.conf&CONF_POST);
|
||||||
curl_easy_setopt(curl, CURLOPT_FTPLISTONLY, config.conf&CONF_FTPLISTONLY);
|
curl_easy_setopt(curl, CURLOPT_FTPLISTONLY,
|
||||||
|
config.conf&CONF_FTPLISTONLY);
|
||||||
curl_easy_setopt(curl, CURLOPT_FTPAPPEND, config.conf&CONF_FTPAPPEND);
|
curl_easy_setopt(curl, CURLOPT_FTPAPPEND, config.conf&CONF_FTPAPPEND);
|
||||||
curl_easy_setopt(curl, CURLOPT_NETRC, config.conf&CONF_NETRC);
|
curl_easy_setopt(curl, CURLOPT_NETRC, config.conf&CONF_NETRC);
|
||||||
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION,
|
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION,
|
||||||
@ -1596,7 +1605,8 @@ int main(int argc, char *argv[])
|
|||||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, config.postfieldsize);
|
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, config.postfieldsize);
|
||||||
|
|
||||||
curl_easy_setopt(curl, CURLOPT_REFERER, config.referer);
|
curl_easy_setopt(curl, CURLOPT_REFERER, config.referer);
|
||||||
curl_easy_setopt(curl, CURLOPT_AUTOREFERER, config.conf&CONF_AUTO_REFERER);
|
curl_easy_setopt(curl, CURLOPT_AUTOREFERER,
|
||||||
|
config.conf&CONF_AUTO_REFERER);
|
||||||
curl_easy_setopt(curl, CURLOPT_USERAGENT, config.useragent);
|
curl_easy_setopt(curl, CURLOPT_USERAGENT, config.useragent);
|
||||||
curl_easy_setopt(curl, CURLOPT_FTPPORT, config.ftpport);
|
curl_easy_setopt(curl, CURLOPT_FTPPORT, config.ftpport);
|
||||||
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, config.low_speed_limit);
|
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, config.low_speed_limit);
|
||||||
@ -1611,7 +1621,8 @@ int main(int argc, char *argv[])
|
|||||||
curl_easy_setopt(curl, CURLOPT_CRLF, config.crlf);
|
curl_easy_setopt(curl, CURLOPT_CRLF, config.crlf);
|
||||||
curl_easy_setopt(curl, CURLOPT_QUOTE, config.quote);
|
curl_easy_setopt(curl, CURLOPT_QUOTE, config.quote);
|
||||||
curl_easy_setopt(curl, CURLOPT_POSTQUOTE, config.postquote);
|
curl_easy_setopt(curl, CURLOPT_POSTQUOTE, config.postquote);
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEHEADER, config.headerfile?&heads:NULL);
|
curl_easy_setopt(curl, CURLOPT_WRITEHEADER,
|
||||||
|
config.headerfile?&heads:NULL);
|
||||||
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, config.cookiefile);
|
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, config.cookiefile);
|
||||||
curl_easy_setopt(curl, CURLOPT_SSLVERSION, config.ssl_version);
|
curl_easy_setopt(curl, CURLOPT_SSLVERSION, config.ssl_version);
|
||||||
curl_easy_setopt(curl, CURLOPT_TIMECONDITION, config.timecond);
|
curl_easy_setopt(curl, CURLOPT_TIMECONDITION, config.timecond);
|
||||||
@ -1667,19 +1678,50 @@ int main(int argc, char *argv[])
|
|||||||
if(headerfilep)
|
if(headerfilep)
|
||||||
fclose(headerfilep);
|
fclose(headerfilep);
|
||||||
|
|
||||||
if(config.url)
|
|
||||||
free(config.url);
|
|
||||||
|
|
||||||
if(url)
|
if(url)
|
||||||
free(url);
|
free(url);
|
||||||
if(config.outfile && !config.remotefile)
|
|
||||||
free(config.outfile);
|
|
||||||
}
|
}
|
||||||
#ifdef MIME_SEPARATORS
|
#ifdef MIME_SEPARATORS
|
||||||
if (separator)
|
if (separator)
|
||||||
printf("--%s--\n", MIMEseparator);
|
printf("--%s--\n", MIMEseparator);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if(config.url)
|
||||||
|
free(config.url);
|
||||||
|
if(config.userpwd)
|
||||||
|
free(config.userpwd);
|
||||||
|
if(config.postfields)
|
||||||
|
free(config.postfields);
|
||||||
|
if(config.proxy)
|
||||||
|
free(config.proxy);
|
||||||
|
if(config.proxyuserpwd)
|
||||||
|
free(config.proxyuserpwd);
|
||||||
|
if(config.cookie)
|
||||||
|
free(config.cookie);
|
||||||
|
if(config.cookiefile)
|
||||||
|
free(config.cookiefile);
|
||||||
|
if(config.krb4level)
|
||||||
|
free(config.krb4level);
|
||||||
|
if(config.headerfile)
|
||||||
|
free(config.headerfile);
|
||||||
|
if(config.outfile)
|
||||||
|
free(config.outfile);
|
||||||
|
if(config.infile)
|
||||||
|
free(config.infile);
|
||||||
|
if(config.range)
|
||||||
|
free(config.range);
|
||||||
|
if(config.customrequest)
|
||||||
|
free(config.customrequest);
|
||||||
|
if(config.writeout)
|
||||||
|
free(config.writeout);
|
||||||
|
|
||||||
|
if(config.httppost)
|
||||||
|
curl_formfree(config.httppost);
|
||||||
|
|
||||||
|
if(allocuseragent)
|
||||||
|
free(config.useragent);
|
||||||
|
|
||||||
/* cleanup memory used for URL globbing patterns */
|
/* cleanup memory used for URL globbing patterns */
|
||||||
glob_cleanup(urls);
|
glob_cleanup(urls);
|
||||||
|
|
||||||
@ -1687,7 +1729,7 @@ int main(int argc, char *argv[])
|
|||||||
curl_slist_free_all(config.postquote); /* */
|
curl_slist_free_all(config.postquote); /* */
|
||||||
curl_slist_free_all(config.headers); /* */
|
curl_slist_free_all(config.headers); /* */
|
||||||
|
|
||||||
return(res);
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *my_get_line(FILE *fp)
|
static char *my_get_line(FILE *fp)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user