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

View File

@ -259,7 +259,7 @@ CURLcode Curl_close(struct SessionHandle *data)
CURLcode Curl_open(struct SessionHandle **curl)
{
/* We don't yet support specifying the URL at this point */
CURLcode res = CURLE_OK;
struct SessionHandle *data;
/* Very simple start-up: alloc the struct, init it with zeroes and return */
data = (struct SessionHandle *)malloc(sizeof(struct SessionHandle));
@ -281,11 +281,9 @@ CURLcode Curl_open(struct SessionHandle **curl)
/* We do some initial setup here, all those fields that can't be just 0 */
data->state.headerbuff=(char*)malloc(HEADERSIZE);
if(!data->state.headerbuff) {
free(data); /* free the memory again */
return CURLE_OUT_OF_MEMORY;
}
if(!data->state.headerbuff)
res = CURLE_OUT_OF_MEMORY;
else {
data->state.headersize=HEADERSIZE;
data->set.out = stdout; /* default output to stdout */
@ -316,25 +314,23 @@ CURLcode Curl_open(struct SessionHandle **curl)
data->set.ssl.numsessions = 5;
data->set.proxyport = 1080;
data->set.proxytype = CURLPROXY_HTTP; /* defaults to HTTP proxy */
data->set.httpauth = CURLAUTH_BASIC; /* defaults to basic authentication */
data->set.proxyauth = CURLAUTH_BASIC; /* defaults to basic authentication */
data->set.httpauth = CURLAUTH_BASIC; /* defaults to basic */
data->set.proxyauth = CURLAUTH_BASIC; /* defaults to basic */
/* 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);
if(!data->state.connects) {
free(data->state.headerbuff);
free(data);
return CURLE_OUT_OF_MEMORY;
}
if(!data->state.connects)
res = CURLE_OUT_OF_MEMORY;
else
memset(data->state.connects, 0,
sizeof(struct connectdata *)*data->state.numconnects);
/*
* libcurl 7.10 introduces SSL verification *by default*! This needs to be
* libcurl 7.10 introduced SSL verification *by default*! This needs to be
* switched off unless wanted.
*/
data->set.ssl.verifypeer = TRUE;
@ -343,9 +339,17 @@ CURLcode Curl_open(struct SessionHandle **curl)
/* This is our prefered CA cert bundle since install time */
data->set.ssl.CAfile = (char *)CURL_CA_BUNDLE;
#endif
}
memset(data->state.connects, 0,
sizeof(struct connectdata *)*data->state.numconnects);
if(res) {
#ifdef USE_ARES
ares_destroy(data->state.areschannel);
#endif
if(data->state.headerbuff)
free(data->state.headerbuff);
free(data);
data = NULL;
}
*curl = data;
return CURLE_OK;