From c5250690f38e4995a9b32d81e406894f92584a38 Mon Sep 17 00:00:00 2001
From: Romain Forlot <romain.forlot@iot.bzh>
Date: Mon, 7 May 2018 14:59:43 +0200
Subject: Improve json object release

For convenience queryJ will always be released. Users has to
call json_object_get to be able to use it after that.
API subcall use an intermediate variable to avoid modifying this
parameter in case of user wanna use it after that.

Change-Id: I98f478d3fc0c4ef28234811333b9effd8289e74d
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
---
 ctl-lib/ctl-action.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

(limited to 'ctl-lib')

diff --git a/ctl-lib/ctl-action.c b/ctl-lib/ctl-action.c
index acad15d..8459449 100644
--- a/ctl-lib/ctl-action.c
+++ b/ctl-lib/ctl-action.c
@@ -63,6 +63,7 @@ PUBLIC void ActionExecOne(CtlSourceT *source, CtlActionT* action, json_object *q
 
             if(queryJ) {
                 json_object_object_foreach(queryJ, key, val) {
+                    json_object_get(val);
                     json_object_object_add(subcallArgsJ, key, val);
                 }
             }
@@ -97,7 +98,6 @@ PUBLIC void ActionExecOne(CtlSourceT *source, CtlActionT* action, json_object *q
             if (err) {
                 AFB_ApiError(action->api, "ActionExecOne(Lua) uid=%s func=%s args=%s", source->uid, action->exec.lua.funcname, json_object_get_string(action->argsJ));
             }
-            json_object_put(queryJ);
             break;
 #endif
 
@@ -106,16 +106,15 @@ PUBLIC void ActionExecOne(CtlSourceT *source, CtlActionT* action, json_object *q
             if (err) {
                 AFB_ApiError(action->api, "ActionExecOne(Callback) uid%s plugin=%s function=%s args=%s", source->uid, action->exec.cb.plugin->uid, action->exec.cb.funcname, json_object_get_string(action->argsJ));
             }
-            json_object_put(queryJ);
             break;
 
         default:
         {
             AFB_ApiError(action->api, "ActionExecOne(unknown) API type uid=%s", source->uid);
-            json_object_put(queryJ);
             break;
         }
     }
+    json_object_put(queryJ);
 }
 
 
-- 
cgit