From 5ab936a92d636390026d466350464ec4182075ac Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Mon, 17 Sep 2012 08:32:44 +0200 Subject: new ruleengine: couple of fixes to new code - memory leak if container was tried to replace - too early free due to invalid reference counting - performance improvement for set statement --- runtime/msg.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/runtime/msg.c b/runtime/msg.c index 0cb60436..2f6606bb 100644 --- a/runtime/msg.c +++ b/runtime/msg.c @@ -3752,9 +3752,9 @@ msgAddJSON(msg_t *pM, uchar *name, struct json_object *json) leaf = jsonPathGetLeaf(name, ustrlen(name)); CHKiRet(jsonPathFindParent(pM, name, leaf, &parent, 1)); leafnode = json_object_object_get(parent, (char*)leaf); - if(leafnode == NULL) + if(leafnode == NULL) { json_object_object_add(parent, (char*)leaf, json); - else { + } else { if(json_object_get_type(json) == json_type_object) { CHKiRet(jsonMerge(pM->json, json)); } else { @@ -3765,9 +3765,17 @@ msgAddJSON(msg_t *pM, uchar *name, struct json_object *json) DBGPRINTF("msgAddJSON: trying to update a container " "node with a leaf, name is '%s' - " "forbidden\n", name); + json_object_put(json); ABORT_FINALIZE(RS_RET_INVLD_SETOP); } - json_object_object_del(parent, (char*)leaf); + /* json-c code indicates we can simply replace a + * json type. Unfortunaltely, this is not documented + * as part of the interface spec. We still use it, + * because it speeds up processing. If it does not work + * at some point, use + * json_object_object_del(parent, (char*)leaf); + * before adding. rgerhards, 2012-09-17 + */ json_object_object_add(parent, (char*)leaf, json); } } @@ -3810,7 +3818,6 @@ DBGPRINTF("AAAA: unset found JSON value path '%s', " "leaf '%s', leafnode %p\n", DBGPRINTF("deleting JSON value path '%s', " "leaf '%s', type %d\n", name, leaf, json_object_get_type(leafnode)); - json_object_put(leafnode); json_object_object_del(parent, (char*)leaf); } } -- cgit v1.2.3