[sr-dev] git:master:641b7b23: utils: Don't leak memory of pkg_realloc returns NULL

Carsten Bock carsten at ng-voice.com
Fri Sep 18 17:25:28 CEST 2015


Module: kamailio
Branch: master
Commit: 641b7b2371b26a9d51b9b5cb0c3918c11ebf6461
URL: https://github.com/kamailio/kamailio/commit/641b7b2371b26a9d51b9b5cb0c3918c11ebf6461

Author: Carsten Bock <carsten at ng-voice.com>
Committer: Carsten Bock <carsten at ng-voice.com>
Date: 2015-09-18T17:25:17+02:00

utils: Don't leak memory of pkg_realloc returns NULL

---

Modified: modules/utils/functions.c

---

Diff:  https://github.com/kamailio/kamailio/commit/641b7b2371b26a9d51b9b5cb0c3918c11ebf6461.diff
Patch: https://github.com/kamailio/kamailio/commit/641b7b2371b26a9d51b9b5cb0c3918c11ebf6461.patch

---

diff --git a/modules/utils/functions.c b/modules/utils/functions.c
index 115cd14..5de92ad 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));
 




More information about the sr-dev mailing list