diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2017-12-04 17:30:02 +0100 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2017-12-11 13:42:51 +0100 |
commit | 9242abc75aab5baf04fc07175f3301ac7dbb8e4b (patch) | |
tree | cb4765b2167eecc37e3964298412cb639d34726d | |
parent | 5a591bb47bdc9d6e2eceda127a749b8bdb92b1a7 (diff) |
Avoid compile warning, memory leaks, linting
Change-Id: Ida18aeab20d5b894609c1a9c2f6fc2a71a0b4a23
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
-rw-r--r-- | ctl-lib/ctl-action.c | 2 | ||||
-rw-r--r-- | ctl-lib/ctl-config.c | 15 | ||||
-rw-r--r-- | ctl-lib/ctl-lua.c | 2 | ||||
-rw-r--r-- | ctl-lib/ctl-plugin.c | 3 |
4 files changed, 14 insertions, 8 deletions
diff --git a/ctl-lib/ctl-action.c b/ctl-lib/ctl-action.c index 8df69d0..fc25d5b 100644 --- a/ctl-lib/ctl-action.c +++ b/ctl-lib/ctl-action.c @@ -54,7 +54,7 @@ PUBLIC void ActionExecUID(AFB_ReqT request, CtlConfigT *ctlConfig, const char *u } PUBLIC void ActionExecOne(CtlSourceT *source, CtlActionT* action, json_object *queryJ) { - int err; + int err = 0; switch (action->type) { case CTL_TYPE_API: diff --git a/ctl-lib/ctl-config.c b/ctl-lib/ctl-config.c index 5325138..1e3de7b 100644 --- a/ctl-lib/ctl-config.c +++ b/ctl-lib/ctl-config.c @@ -56,6 +56,7 @@ PUBLIC json_object* CtlConfigScan(const char *dirList, const char *prefix) { char* ConfigSearch(AFB_ApiT apiHandle, json_object *responseJ) { // We load 1st file others are just warnings + char filepath[CONTROL_MAXPATH_LEN]; for (int index = 0; index < json_object_array_length(responseJ); index++) { json_object *entryJ = json_object_array_get_idx(responseJ, index); @@ -64,20 +65,17 @@ char* ConfigSearch(AFB_ApiT apiHandle, json_object *responseJ) { int err = wrap_json_unpack(entryJ, "{s:s, s:s !}", "fullpath", &fullpath, "filename", &filename); if (err) { AFB_ApiError(apiHandle, "CTL-INIT HOOPs invalid JSON entry= %s", json_object_get_string(entryJ)); - return NULL; } if (index == 0) { - char filepath[CONTROL_MAXPATH_LEN]; strncpy(filepath, fullpath, strlen(fullpath)+1); strncat(filepath, "/", strlen("/")); strncat(filepath, filename, strlen(filename)); - return (strdup(filepath)); } } - // no config found - return NULL; + json_object_put(responseJ); + return strndup(filepath, sizeof(filepath)); } PUBLIC char* CtlConfigSearch(AFB_ApiT apiHandle, const char *dirList, const char *prefix) { @@ -163,7 +161,7 @@ PUBLIC CtlConfigT *CtlLoadMetaData(AFB_ApiT apiHandle, const char* filepath) { return ctlHandle; OnErrorExit: - if (ctlHandle) free(ctlHandle); + free(ctlHandle); return NULL; } @@ -197,6 +195,8 @@ json_object* CtlUpdateSectionConfig(AFB_ApiT apiHandle, CtlConfigT *ctlHandle, c if (oneFile) { json_object *newSectionJ, *newFileJ = json_object_from_file(oneFile); json_object_object_get_ex(newFileJ, key, &newSectionJ); + json_object_get(newSectionJ); + json_object_put(newFileJ); LoadAdditionalsFiles(apiHandle, ctlHandle, key, newSectionJ); json_object_object_get_ex(ctlHandle->configJ, key, §ionArrayJ); wrap_json_optarray_for_all(newSectionJ, wrap_json_array_add, sectionArrayJ); @@ -245,7 +245,8 @@ json_object* LoadAdditionalsFiles(AFB_ApiT apiHandle, CtlConfigT *ctlHandle, con } if(json_object_array_length(filesArrayJ) > 0) - return CtlUpdateSectionConfig(apiHandle, ctlHandle, key, sectionJ, filesArrayJ); + sectionJ = CtlUpdateSectionConfig(apiHandle, ctlHandle, key, sectionJ, filesArrayJ); + json_object_put(filesArrayJ); return sectionJ; } diff --git a/ctl-lib/ctl-lua.c b/ctl-lib/ctl-lua.c index f80668e..f8ab69d 100644 --- a/ctl-lib/ctl-lua.c +++ b/ctl-lib/ctl-lua.c @@ -1267,6 +1267,7 @@ PUBLIC int LuaConfigLoad (AFB_ApiT apiHandle) { return 0; OnErrorExit: + free(luaState); return 1; } @@ -1324,6 +1325,7 @@ PUBLIC int LuaConfigExec (AFB_ApiT apiHandle, const char* prefix) { } } + json_object_put(luaScriptPathJ); // no policy config found remove control API from binder if (index == 0) { AFB_ApiWarning (apiHandle, "POLICY-INIT:WARNING (setenv CONTROL_LUA_PATH) No LUA '%s*.lua' in '%s'", fullprefix, dirList); diff --git a/ctl-lib/ctl-plugin.c b/ctl-lib/ctl-plugin.c index 6ec1ace..be3cf67 100644 --- a/ctl-lib/ctl-plugin.c +++ b/ctl-lib/ctl-plugin.c @@ -206,9 +206,12 @@ STATIC int PluginLoadOne (AFB_ApiT apiHandle, CtlPluginT *ctlPlugin, json_object ctlPlugin->api = apiHandle; ctlPlugin->context = (*ctlPluginOnload) (ctlPlugin, handle); } + + json_object_put(pluginPathJ); // No more needs for that json_object. return 0; OnErrorExit: + json_object_put(pluginPathJ); // No more needs for that json_object. return 1; } |