diff options
author | Daniel Stenberg <daniel@haxx.se> | 2003-10-24 12:58:29 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2003-10-24 12:58:29 +0000 |
commit | 7247041e219c0281b9ff0835eada711593b9d62f (patch) | |
tree | 41ed63a63002ec48549c7173f9058a8442fce37c | |
parent | 017a78d0c50e2e049c2111065e9c5d4e1e49e533 (diff) |
Improved checks for bad memory situations and proper behaviour when we
run out of memory.
-rw-r--r-- | lib/http.c | 50 |
1 files changed, 33 insertions, 17 deletions
diff --git a/lib/http.c b/lib/http.c index 2f7db943b..4543faee8 100644 --- a/lib/http.c +++ b/lib/http.c @@ -591,7 +591,6 @@ CURLcode add_buffer_send(send_buffer *in, static CURLcode add_bufferf(send_buffer *in, const char *fmt, ...) { - CURLcode result = CURLE_OUT_OF_MEMORY; char *s; va_list ap; va_start(ap, fmt); @@ -599,10 +598,16 @@ CURLcode add_bufferf(send_buffer *in, const char *fmt, ...) va_end(ap); if(s) { - result = add_buffer(in, s, strlen(s)); + CURLcode result = add_buffer(in, s, strlen(s)); free(s); + if(CURLE_OK == result) + return CURLE_OK; } - return result; + /* If we failed, we cleanup the whole buffer and return error */ + if(in->buffer) + free(in->buffer); + free(in); + return CURLE_OUT_OF_MEMORY; } /* @@ -1152,6 +1157,10 @@ CURLcode Curl_http(struct connectdata *conn) host, conn->bits.ipv6_ip?"]":"", conn->remote_port); + + if(!conn->allocptr.host) + /* without Host: we can't make a nice request */ + return CURLE_OUT_OF_MEMORY; } if(data->cookies) { @@ -1290,21 +1299,25 @@ CURLcode Curl_http(struct connectdata *conn) /* initialize a dynamic send-buffer */ req_buffer = add_buffer_init(); + if(!req_buffer) + return CURLE_OUT_OF_MEMORY; + /* add the main request stuff */ - add_bufferf(req_buffer, - "%s " /* GET/HEAD/POST/PUT */ - "%s HTTP/%s\r\n" /* path + HTTP version */ - "%s" /* proxyuserpwd */ - "%s" /* userpwd */ - "%s" /* range */ - "%s" /* user agent */ - "%s" /* cookie */ - "%s" /* host */ - "%s" /* pragma */ - "%s" /* accept */ - "%s" /* accept-encoding */ - "%s" /* referer */ - "%s",/* transfer-encoding */ + result = + add_bufferf(req_buffer, + "%s " /* GET/HEAD/POST/PUT */ + "%s HTTP/%s\r\n" /* path + HTTP version */ + "%s" /* proxyuserpwd */ + "%s" /* userpwd */ + "%s" /* range */ + "%s" /* user agent */ + "%s" /* cookie */ + "%s" /* host */ + "%s" /* pragma */ + "%s" /* accept */ + "%s" /* accept-encoding */ + "%s" /* referer */ + "%s",/* transfer-encoding */ request, ppath, @@ -1326,6 +1339,9 @@ CURLcode Curl_http(struct connectdata *conn) te ); + if(result) + return result; + if(co) { int count=0; struct Cookie *store=co; |