From 641b7b2371b26a9d51b9b5cb0c3918c11ebf6461 Mon Sep 17 00:00:00 2001 From: Carsten Bock Date: Fri, 18 Sep 2015 17:25:03 +0200 Subject: [PATCH] utils: Don't leak memory of pkg_realloc returns NULL --- modules/utils/functions.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/utils/functions.c b/modules/utils/functions.c index 115cd14a739..5de92ad8763 100644 --- a/modules/utils/functions.c +++ b/modules/utils/functions.c @@ -58,13 +58,14 @@ size_t write_function( void *ptr, size_t size, size_t nmemb, void *stream_ptr) { http_res_stream_t *stream = (http_res_stream_t *) stream_ptr; - stream->buf = (char *) pkg_realloc(stream->buf, stream->curr_size + + char *tmp = (char *) pkg_realloc(stream->buf, stream->curr_size + (size * nmemb)); - if (stream->buf == NULL) { + if (tmp == NULL) { LM_ERR("cannot allocate memory for stream\n"); return CURLE_WRITE_ERROR; } + stream->buf = tmp; memcpy(&stream->buf[stream->pos], (char *) ptr, (size * nmemb));