From 12e7a8c3d609d6a6094a7db8fb8c0cc80d8f55f0 Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Sat, 29 Apr 2017 18:52:51 +0200 Subject: url: fixed a memory leak on OOM while setting CURLOPT_BUFFERSIZE --- lib/url.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/url.c b/lib/url.c index f5998d6b1..4fc2f4cad 100644 --- a/lib/url.c +++ b/lib/url.c @@ -2293,12 +2293,13 @@ CURLcode Curl_setopt(struct Curl_easy *data, CURLoption option, /* Resize only if larger than default buffer size. */ if(data->set.buffer_size > BUFSIZE) { - data->state.buffer = realloc(data->state.buffer, - data->set.buffer_size + 1); - if(!data->state.buffer) { + char *newbuff = realloc(data->state.buffer, data->set.buffer_size + 1); + if(!newbuff) { DEBUGF(fprintf(stderr, "Error: realloc of buffer failed\n")); result = CURLE_OUT_OF_MEMORY; } + else + data->state.buffer = newbuff; } break; -- cgit v1.2.3