aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2004-05-11 21:17:03 +0000
committerDaniel Stenberg <daniel@haxx.se>2004-05-11 21:17:03 +0000
commit98f968f2eef9adc29f1702c09bd7d6306e338a55 (patch)
tree4ac3829b2e9c006dd98e3f9dc10e9e0e1ed4f3d1 /lib
parent864f1a33666135db5a30c712a8fb189a5cbccba4 (diff)
fixed Curl_open() to not leak anything if one malloc() fails, fix by
James Bursa only modified by me.
Diffstat (limited to 'lib')
-rw-r--r--lib/url.c104
1 files changed, 54 insertions, 50 deletions
diff --git a/lib/url.c b/lib/url.c
index 66012ef32..4b13c3634 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -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,71 +281,75 @@ 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;
- }
-
- 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 */
-
- /* use fwrite as default function to store output */
- data->set.fwrite = (curl_write_callback)fwrite;
+ if(!data->state.headerbuff)
+ res = CURLE_OUT_OF_MEMORY;
+ else {
+ data->state.headersize=HEADERSIZE;
- /* use fread as default function to read input */
- data->set.fread = (curl_read_callback)fread;
+ 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.infilesize = -1; /* we don't know any size */
+ /* use fwrite as default function to store output */
+ data->set.fwrite = (curl_write_callback)fwrite;
- data->state.current_speed = -1; /* init to negative == impossible */
+ /* use fread as default function to read input */
+ data->set.fread = (curl_read_callback)fread;
- 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.infilesize = -1; /* we don't know any size */
- data->set.dns_cache_timeout = 60; /* Timeout every 60 seconds by default */
+ data->state.current_speed = -1; /* init to negative == impossible */
- /* make libcurl quiet by default: */
- data->set.hide_progress = TRUE; /* CURLOPT_NOPROGRESS changes these */
- data->progress.flags |= PGRS_HIDE;
+ 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 */
- /* Set the default size of the SSL session ID cache */
- data->set.ssl.numsessions = 5;
+ data->set.dns_cache_timeout = 60; /* Timeout every 60 seconds by default */
- data->set.proxyport = 1080;
+ /* make libcurl quiet by default: */
+ data->set.hide_progress = TRUE; /* CURLOPT_NOPROGRESS changes these */
+ data->progress.flags |= PGRS_HIDE;
- data->set.proxytype = CURLPROXY_HTTP; /* defaults to HTTP proxy */
+ /* Set the default size of the SSL session ID cache */
+ data->set.ssl.numsessions = 5;
- data->set.httpauth = CURLAUTH_BASIC; /* defaults to basic authentication */
- data->set.proxyauth = CURLAUTH_BASIC; /* defaults to basic authentication */
+ data->set.proxyport = 1080;
+ 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 */
- /* 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);
+ /* 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
- * switched off unless wanted.
- */
- data->set.ssl.verifypeer = TRUE;
- data->set.ssl.verifyhost = 2;
+ /*
+ * libcurl 7.10 introduced 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
- /* This is our prefered CA cert bundle since install time */
- data->set.ssl.CAfile = (char *)CURL_CA_BUNDLE;
+ /* 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;