Module: sip-router
Branch: 4.0
Commit: e667cf0f35aab18ccd73f5bfe85857ddf3508ef8
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=e667cf0…
Author: Juha Heinanen <jh(a)tutpro.com>
Committer: Juha Heinanen <jh(a)tutpro.com>
Date: Wed Feb 19 01:37:21 2014 +0200
modules/utils: http_query fixes
- Credits to Guillaume Bour.
---
modules/utils/functions.c | 12 ++++++++----
1 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/modules/utils/functions.c b/modules/utils/functions.c
index aadfdd5..660050d 100644
--- a/modules/utils/functions.c
+++ b/modules/utils/functions.c
@@ -51,7 +51,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;
@@ -76,7 +76,7 @@ int http_query(struct sip_msg* _m, char* _url, char* _dst)
CURLcode res;
str value;
char *url, *at;
- char* stream;
+ char* stream = NULL;
long stat;
pv_spec_t *dst;
pv_value_t val;
@@ -112,10 +112,12 @@ int http_query(struct sip_msg* _m, char* _url, char* _dst)
res = curl_easy_perform(curl);
pkg_free(url);
- 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;
}
@@ -131,11 +133,13 @@ int http_query(struct sip_msg* _m, char* _url, char* _dst)
}
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;
}