From 7247041e219c0281b9ff0835eada711593b9d62f Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 24 Oct 2003 12:58:29 +0000 Subject: Improved checks for bad memory situations and proper behaviour when we run out of memory. --- lib/http.c | 50 +++++++++++++++++++++++++++++++++----------------- 1 file 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; -- cgit v1.2.3