Module: kamailio
Branch: 4.3
Commit: 7881ec8d3cd5aa347424108f1fb9860c383e01d5
URL:
https://github.com/kamailio/kamailio/commit/7881ec8d3cd5aa347424108f1fb9860…
Author: Carsten Bock <carsten(a)ng-voice.com>
Committer: Carsten Bock <carsten(a)ng-voice.com>
Date: 2015-09-18T17:26:10+02:00
utils: Don't leak memory of pkg_realloc returns NULL
---
Modified: modules/utils/functions.c
---
Diff:
https://github.com/kamailio/kamailio/commit/7881ec8d3cd5aa347424108f1fb9860…
Patch:
https://github.com/kamailio/kamailio/commit/7881ec8d3cd5aa347424108f1fb9860…
---
diff --git a/modules/utils/functions.c b/modules/utils/functions.c
index f261cc0..97d1700 100644
--- a/modules/utils/functions.c
+++ b/modules/utils/functions.c
@@ -54,13 +54,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));