From c54d3d5e8cb45f2ad1b0166524f6407172df80c8 Mon Sep 17 00:00:00 2001 From: Julien Thomas Date: Fri, 9 Oct 2020 21:21:10 +0200 Subject: [PATCH 70/73] msg: memory leak in msgAddJSON() if jsonPathFindParent() failed There is a missing call to json_object_put(json) if the call to jsonPathFindParent() failed. It's leaking memory. --- runtime/msg.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/runtime/msg.c b/runtime/msg.c index 8e86d2944..0dc86c0ed 100644 --- a/runtime/msg.c +++ b/runtime/msg.c @@ -4966,7 +4966,11 @@ msgAddJSON(smsg_t * const pM, uchar *name, struct json_object *json, int force_r *jroot = json_object_new_object(); } leaf = jsonPathGetLeaf(name, ustrlen(name)); - CHKiRet(jsonPathFindParent(*jroot, name, leaf, &parent, 1)); + iRet = jsonPathFindParent(*jroot, name, leaf, &parent, 1); + if (unlikely(iRet != RS_RET_OK)) { + json_object_put(json); + FINALIZE; + } if (json_object_get_type(parent) != json_type_object) { DBGPRINTF("msgAddJSON: not a container in json path," "name is '%s'\n", name); -- 2.23.0