Skip to content

Commit

Permalink
utils: Don't leak memory of pkg_realloc returns NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
carstenbock committed Sep 18, 2015
1 parent f81d8cc commit 641b7b2
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions modules/utils/functions.c
Expand Up @@ -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));

Expand Down

0 comments on commit 641b7b2

Please sign in to comment.