Module: sip-router
Branch: tmp/interconnectroute_module
Commit: def8d2600422a442b971c204df98594b0dfdaacd
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=def8d26…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Wed Nov 5 14:29:34 2014 +0100
json: unreference the json object in json_get_field()
- the parsed json object has to be freed
- reported by dongwflj(a)163.com
---
modules/json/json_funcs.c | 21 +++++++++++++--------
1 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/modules/json/json_funcs.c b/modules/json/json_funcs.c
index f7233cb..106eef1 100644
--- a/modules/json/json_funcs.c
+++ b/modules/json/json_funcs.c
@@ -33,10 +33,12 @@
int json_get_field(struct sip_msg* msg, char* json, char* field, char* dst)
{
- str json_s;
- str field_s;
- pv_spec_t *dst_pv;
- pv_value_t dst_val;
+ str json_s;
+ str field_s;
+ pv_spec_t *dst_pv;
+ pv_value_t dst_val;
+ char *value;
+ struct json_object *j = NULL;
if (fixup_get_svalue(msg, (gparam_p)json, &json_s) != 0) {
LM_ERR("cannot get json string value\n");
@@ -47,22 +49,25 @@ int json_get_field(struct sip_msg* msg, char* json, char* field, char*
dst)
LM_ERR("cannot get field string value\n");
return -1;
}
-
+
dst_pv = (pv_spec_t *)dst;
-
- struct json_object *j = json_tokener_parse(json_s.s);
+
+
+ j = json_tokener_parse(json_s.s);
if (is_error(j)) {
LM_ERR("empty or invalid JSON\n");
+ if(j!=NULL) json_object_put(j);
return -1;
}
- char *value = (char*)json_object_to_json_string(json_object_object_get(j, field_s.s));
+ value = (char*)json_object_to_json_string(json_object_object_get(j, field_s.s));
dst_val.rs.s = value;
dst_val.rs.len = strlen(value);
dst_val.flags = PV_VAL_STR;
dst_pv->setf(msg, &dst_pv->pvp, (int)EQ_T, &dst_val);
+ if(j!=NULL) json_object_put(j);
return 1;
}