aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2004-05-04 13:39:24 +0000
committerDaniel Stenberg <daniel@haxx.se>2004-05-04 13:39:24 +0000
commit08d1da106ebe3817ce3aad083182fad4881a8d2a (patch)
tree778181c3f8a70113e8f8937b617dd8f53605f965
parent9e31a0536e7d0d5abe78673a6d384d2f7fc87bd5 (diff)
check malloc() return code
-rw-r--r--lib/http.c29
1 files changed, 16 insertions, 13 deletions
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;