OK, I pushed it to branches 4.2 and 4.1
Cheers, Daniel
On 06/11/14 11:15, dongwf wrote:
Hi, I checked with my test env, your fix is ok, please port, thanks!
At 2014-11-05 21:35:40, "Daniel-Constantin Mierla" miconda@gmail.com wrote:
Hello, I pushed a fix that should release the json object: - http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=def8d2600422a442b971c204df98594b0dfdaacd dst_pv->setf() should copy (clone) of the string value and then the object can be unreferenced. If works ok, then I will backport -- I didn't have any server with json library at hand to give it a minimum test. Cheers, Daniel On 05/11/14 11:23, dongwf wrote:
One more question based the last mail, if I want to return the j object pointer via PV to script( created as struct json_object *j = json_tokener_parse(json_s.s);), how can I achieve that? Then I can put the pointer back to another exported api and release the pointer via json_object_put, thanks! At 2014-11-05 17:54:46, "dongwf" <dongwflj@163.com> wrote: Hi: I am trying to use json module in script with json_get_field exported api, I found in it's implementation, the api will call struct json_object *j = json_tokener_parse(json_s.s); but didn't call json_object_put for this j object, then the object will leak. So my question is how to release the new j object? We can't release in json_get_field(), that will cause the returned string become to rubbish, thanks! Below is the api's code in module\json\json_funcs.c: 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; if (fixup_get_svalue(msg, (gparam_p)json, &json_s) != 0) { LM_ERR("cannot get json string value\n"); return -1; } if (fixup_get_svalue(msg, (gparam_p)field, &field_s) != 0) { 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); if (is_error(j)) { LM_ERR("empty or invalid JSON\n"); return -1; } char *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); return 1; } _______________________________________________ SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list sr-users@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
-- Daniel-Constantin Mierla http://twitter.com/#!/miconda - http://www.linkedin.com/in/miconda Kamailio Advanced Training, Nov 24-27, Berlin - http://www.asipto.com