[sr-dev] git:master: modules/utils: fixed memory leak and possible crash

Juha Heinanen jh at tutpro.com
Sat Feb 15 03:17:23 CET 2014


Module: sip-router
Branch: master
Commit: 92b947059dbde8ada3c757d7e6af48d79f9e7e12
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=92b947059dbde8ada3c757d7e6af48d79f9e7e12

Author: Juha Heinanen <jh at tutpro.com>
Committer: Juha Heinanen <jh at tutpro.com>
Date:   Sat Feb 15 04:16:14 2014 +0200

modules/utils: fixed memory leak and possible crash

- patch against 4.0 was provided by Guillaume Bour

---

 modules/utils/functions.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/modules/utils/functions.c b/modules/utils/functions.c
index 1225ba8..ed1a591 100644
--- a/modules/utils/functions.c
+++ b/modules/utils/functions.c
@@ -52,7 +52,7 @@ size_t write_function( void *ptr, size_t size, size_t nmemb, void *stream)
     /* Allocate memory and copy */
     char* data;
 
-    data = (char*)malloc((size* nmemb) + 1);
+    data = (char*)pkg_malloc((size* nmemb) + 1);
     if (data == NULL) {
 	LM_ERR("cannot allocate memory for stream\n");
 	return CURLE_WRITE_ERROR;
@@ -138,10 +138,12 @@ int http_query(struct sip_msg* _m, char* _url, char* _dst, char* _post)
     if (_post) {
 	pkg_free(post);
     }
-    curl_easy_cleanup(curl);
 
     if (res != CURLE_OK) {
 	LM_ERR("failed to perform curl\n");
+	curl_easy_cleanup(curl);
+	if(stream)
+	    pkg_free(stream);
 	return -1;
     }
 
@@ -157,11 +159,13 @@ int http_query(struct sip_msg* _m, char* _url, char* _dst, char* _post)
 	}
 	val.rs.s = stream;
 	val.rs.len = at - stream;
-	LM_DBG("http)query result: %.*s\n", val.rs.len, val.rs.s);
+	LM_DBG("http_query result: %.*s\n", val.rs.len, val.rs.s);
 	val.flags = PV_VAL_STR;
 	dst = (pv_spec_t *)_dst;
 	dst->setf(_m, &dst->pvp, (int)EQ_T, &val);
     }
 	
+    curl_easy_cleanup(curl);
+    pkg_free(stream);
     return stat;
 }




More information about the sr-dev mailing list