1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-21 23:58:49 -05:00

fixed Curl_open() to not leak anything if one malloc() fails, fix by

James Bursa only modified by me.
This commit is contained in:
Daniel Stenberg 2004-05-11 21:17:03 +00:00
parent 864f1a3366
commit 98f968f2ee

104
lib/url.c
View File

@ -259,7 +259,7 @@ CURLcode Curl_close(struct SessionHandle *data)
CURLcode Curl_open(struct SessionHandle **curl) CURLcode Curl_open(struct SessionHandle **curl)
{ {
/* We don't yet support specifying the URL at this point */ CURLcode res = CURLE_OK;
struct SessionHandle *data; struct SessionHandle *data;
/* Very simple start-up: alloc the struct, init it with zeroes and return */ /* Very simple start-up: alloc the struct, init it with zeroes and return */
data = (struct SessionHandle *)malloc(sizeof(struct SessionHandle)); data = (struct SessionHandle *)malloc(sizeof(struct SessionHandle));
@ -281,71 +281,75 @@ CURLcode Curl_open(struct SessionHandle **curl)
/* We do some initial setup here, all those fields that can't be just 0 */ /* We do some initial setup here, all those fields that can't be just 0 */
data->state.headerbuff=(char*)malloc(HEADERSIZE); data->state.headerbuff=(char*)malloc(HEADERSIZE);
if(!data->state.headerbuff) { if(!data->state.headerbuff)
free(data); /* free the memory again */ res = CURLE_OUT_OF_MEMORY;
return CURLE_OUT_OF_MEMORY; else {
} data->state.headersize=HEADERSIZE;
data->state.headersize=HEADERSIZE; data->set.out = stdout; /* default output to stdout */
data->set.in = stdin; /* default input from stdin */
data->set.err = stderr; /* default stderr to stderr */
data->set.out = stdout; /* default output to stdout */ /* use fwrite as default function to store output */
data->set.in = stdin; /* default input from stdin */ data->set.fwrite = (curl_write_callback)fwrite;
data->set.err = stderr; /* default stderr to stderr */
/* use fwrite as default function to store output */ /* use fread as default function to read input */
data->set.fwrite = (curl_write_callback)fwrite; data->set.fread = (curl_read_callback)fread;
/* use fread as default function to read input */ data->set.infilesize = -1; /* we don't know any size */
data->set.fread = (curl_read_callback)fread;
data->set.infilesize = -1; /* we don't know any size */ data->state.current_speed = -1; /* init to negative == impossible */
data->state.current_speed = -1; /* init to negative == impossible */ data->set.httpreq = HTTPREQ_GET; /* Default HTTP request */
data->set.ftp_use_epsv = TRUE; /* FTP defaults to EPSV operations */
data->set.ftp_use_eprt = TRUE; /* FTP defaults to EPRT operations */
data->set.httpreq = HTTPREQ_GET; /* Default HTTP request */ data->set.dns_cache_timeout = 60; /* Timeout every 60 seconds by default */
data->set.ftp_use_epsv = TRUE; /* FTP defaults to EPSV operations */
data->set.ftp_use_eprt = TRUE; /* FTP defaults to EPRT operations */
data->set.dns_cache_timeout = 60; /* Timeout every 60 seconds by default */ /* make libcurl quiet by default: */
data->set.hide_progress = TRUE; /* CURLOPT_NOPROGRESS changes these */
data->progress.flags |= PGRS_HIDE;
/* make libcurl quiet by default: */ /* Set the default size of the SSL session ID cache */
data->set.hide_progress = TRUE; /* CURLOPT_NOPROGRESS changes these */ data->set.ssl.numsessions = 5;
data->progress.flags |= PGRS_HIDE;
/* Set the default size of the SSL session ID cache */ data->set.proxyport = 1080;
data->set.ssl.numsessions = 5; data->set.proxytype = CURLPROXY_HTTP; /* defaults to HTTP proxy */
data->set.httpauth = CURLAUTH_BASIC; /* defaults to basic */
data->set.proxyauth = CURLAUTH_BASIC; /* defaults to basic */
data->set.proxyport = 1080; /* create an array with connection data struct pointers */
data->state.numconnects = 5; /* hard-coded right now */
data->state.connects = (struct connectdata **)
malloc(sizeof(struct connectdata *) * data->state.numconnects);
data->set.proxytype = CURLPROXY_HTTP; /* defaults to HTTP proxy */ if(!data->state.connects)
res = CURLE_OUT_OF_MEMORY;
else
memset(data->state.connects, 0,
sizeof(struct connectdata *)*data->state.numconnects);
data->set.httpauth = CURLAUTH_BASIC; /* defaults to basic authentication */ /*
data->set.proxyauth = CURLAUTH_BASIC; /* defaults to basic authentication */ * libcurl 7.10 introduced SSL verification *by default*! This needs to be
* switched off unless wanted.
/* create an array with connection data struct pointers */ */
data->state.numconnects = 5; /* hard-coded right now */ data->set.ssl.verifypeer = TRUE;
data->state.connects = (struct connectdata **) data->set.ssl.verifyhost = 2;
malloc(sizeof(struct connectdata *) * data->state.numconnects);
if(!data->state.connects) {
free(data->state.headerbuff);
free(data);
return CURLE_OUT_OF_MEMORY;
}
/*
* libcurl 7.10 introduces SSL verification *by default*! This needs to be
* switched off unless wanted.
*/
data->set.ssl.verifypeer = TRUE;
data->set.ssl.verifyhost = 2;
#ifdef CURL_CA_BUNDLE #ifdef CURL_CA_BUNDLE
/* This is our prefered CA cert bundle since install time */ /* This is our prefered CA cert bundle since install time */
data->set.ssl.CAfile = (char *)CURL_CA_BUNDLE; data->set.ssl.CAfile = (char *)CURL_CA_BUNDLE;
#endif #endif
}
memset(data->state.connects, 0, if(res) {
sizeof(struct connectdata *)*data->state.numconnects); #ifdef USE_ARES
ares_destroy(data->state.areschannel);
#endif
if(data->state.headerbuff)
free(data->state.headerbuff);
free(data);
data = NULL;
}
*curl = data; *curl = data;
return CURLE_OK; return CURLE_OK;