From 08d1da106ebe3817ce3aad083182fad4881a8d2a Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 4 May 2004 13:39:24 +0000 Subject: check malloc() return code --- lib/http.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'lib') diff --git a/lib/http.c b/lib/http.c index b8243b35a..cc0ef7f8c 100644 --- a/lib/http.c +++ b/lib/http.c @@ -1430,19 +1430,22 @@ CURLcode Curl_http(struct connectdata *conn) char *newurl; newurl = malloc(urllen + newlen - currlen + 1); - - /* copy the part before the host name */ - memcpy(newurl, url, ptr - url); - /* append the new host name instead of the old */ - memcpy(newurl + (ptr - url), conn->host.name, newlen); - /* append the piece after the host name */ - memcpy(newurl + newlen + (ptr - url), - ptr + currlen, /* copy the trailing zero byte too */ - urllen - (ptr-url) - currlen + 1); - if(data->change.url_alloc) - free(data->change.url); - data->change.url = newurl; - data->change.url_alloc = TRUE; + if(newurl) { + /* copy the part before the host name */ + memcpy(newurl, url, ptr - url); + /* append the new host name instead of the old */ + memcpy(newurl + (ptr - url), conn->host.name, newlen); + /* append the piece after the host name */ + memcpy(newurl + newlen + (ptr - url), + ptr + currlen, /* copy the trailing zero byte too */ + urllen - (ptr-url) - currlen + 1); + if(data->change.url_alloc) + free(data->change.url); + data->change.url = newurl; + data->change.url_alloc = TRUE; + } + else + return CURLE_OUT_OF_MEMORY; } } ppath = data->change.url; -- cgit v1.2.3