Improved checks for bad memory situations and proper behaviour when we

run out of memory.
This commit is contained in:
Daniel Stenberg 2003-10-24 12:58:29 +00:00
parent 017a78d0c5
commit 7247041e21

View File

@ -591,7 +591,6 @@ CURLcode add_buffer_send(send_buffer *in,
static static
CURLcode add_bufferf(send_buffer *in, const char *fmt, ...) CURLcode add_bufferf(send_buffer *in, const char *fmt, ...)
{ {
CURLcode result = CURLE_OUT_OF_MEMORY;
char *s; char *s;
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
@ -599,10 +598,16 @@ CURLcode add_bufferf(send_buffer *in, const char *fmt, ...)
va_end(ap); va_end(ap);
if(s) { if(s) {
result = add_buffer(in, s, strlen(s)); CURLcode result = add_buffer(in, s, strlen(s));
free(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, host,
conn->bits.ipv6_ip?"]":"", conn->bits.ipv6_ip?"]":"",
conn->remote_port); conn->remote_port);
if(!conn->allocptr.host)
/* without Host: we can't make a nice request */
return CURLE_OUT_OF_MEMORY;
} }
if(data->cookies) { if(data->cookies) {
@ -1290,21 +1299,25 @@ CURLcode Curl_http(struct connectdata *conn)
/* initialize a dynamic send-buffer */ /* initialize a dynamic send-buffer */
req_buffer = add_buffer_init(); req_buffer = add_buffer_init();
if(!req_buffer)
return CURLE_OUT_OF_MEMORY;
/* add the main request stuff */ /* add the main request stuff */
add_bufferf(req_buffer, result =
"%s " /* GET/HEAD/POST/PUT */ add_bufferf(req_buffer,
"%s HTTP/%s\r\n" /* path + HTTP version */ "%s " /* GET/HEAD/POST/PUT */
"%s" /* proxyuserpwd */ "%s HTTP/%s\r\n" /* path + HTTP version */
"%s" /* userpwd */ "%s" /* proxyuserpwd */
"%s" /* range */ "%s" /* userpwd */
"%s" /* user agent */ "%s" /* range */
"%s" /* cookie */ "%s" /* user agent */
"%s" /* host */ "%s" /* cookie */
"%s" /* pragma */ "%s" /* host */
"%s" /* accept */ "%s" /* pragma */
"%s" /* accept-encoding */ "%s" /* accept */
"%s" /* referer */ "%s" /* accept-encoding */
"%s",/* transfer-encoding */ "%s" /* referer */
"%s",/* transfer-encoding */
request, request,
ppath, ppath,
@ -1326,6 +1339,9 @@ CURLcode Curl_http(struct connectdata *conn)
te te
); );
if(result)
return result;
if(co) { if(co) {
int count=0; int count=0;
struct Cookie *store=co; struct Cookie *store=co;