From 6b3eba09020a87b060628058a8ac29403c859cd2 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Mon, 27 Jun 2022 14:56:39 -0400 Subject: [PATCH] TT#182200 fix mem leak json_tokener_parse returns a newly created JSON object (tree) which must be freed by decreasing the ref count before the variable goes out of scope. Fix-up for Ia7e8446fe4953d1391f99ea1530990e3d385c056 Change-Id: I2e4b17086df468f66401a71a836d37ed821944e5 (cherry picked from commit 056f1ae6100c83209792c18f82c6b96d6ba25f45) --- cdr.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/cdr.c b/cdr.c index 2495eb1..d0cfcc7 100644 --- a/cdr.c +++ b/cdr.c @@ -1302,17 +1302,25 @@ static int validate_src_dst_leg(med_entry_t *e) return -1; } + int invalid; + json_object *json_src_leg = json_tokener_parse(e->src_leg); - if (!(json_src_leg && json_object_is_type(json_src_leg, json_type_object)) && - strchr(e->src_leg, MED_SEP) == NULL) + invalid = (!(json_src_leg && json_object_is_type(json_src_leg, json_type_object)) && + strchr(e->src_leg, MED_SEP) == NULL); + if (json_src_leg) + json_object_put(json_src_leg); + if (invalid) { L_DEBUG("Invalid src_leg"); return -1; } json_object *json_dst_leg = json_tokener_parse(e->dst_leg); - if (!(json_dst_leg && json_object_is_type(json_dst_leg, json_type_object)) && - strchr(e->dst_leg, MED_SEP) == NULL) + invalid = (!(json_dst_leg && json_object_is_type(json_dst_leg, json_type_object)) && + strchr(e->dst_leg, MED_SEP) == NULL); + if (json_dst_leg) + json_object_put(json_dst_leg); + if (invalid) { L_DEBUG("Invalid dst_leg"); return -1;