From 32b3ba79b44fc42d0a5767f7a24bb283c2de3034 Mon Sep 17 00:00:00 2001 From: Klas Lindfors Date: Thu, 25 Apr 2013 10:57:14 +0200 Subject: [PATCH] make sure json objects are released on error conditions --- ykpers-json.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/ykpers-json.c b/ykpers-json.c index 1c19e3e..5425f75 100644 --- a/ykpers-json.c +++ b/ykpers-json.c @@ -180,6 +180,7 @@ int _ykp_json_export_cfg(const YKP_CONFIG *cfg, char *json, size_t len) { } int _ykp_json_import_cfg(YKP_CONFIG *cfg, const char *json, size_t len) { + int ret_code = 0; if(cfg) { json_object *jobj = json_tokener_parse(json); json_object *yprod_json = json_object_object_get(jobj, "yubiProdConfig"); @@ -197,7 +198,7 @@ int _ykp_json_import_cfg(YKP_CONFIG *cfg, const char *json, size_t len) { if(!jobj || !yprod_json || !jmode || !options) { ykp_errno = YKP_EINVAL; - return 0; + goto out; } jtarget = json_object_object_get(yprod_json, "targetConfig"); @@ -206,11 +207,11 @@ int _ykp_json_import_cfg(YKP_CONFIG *cfg, const char *json, size_t len) { if(target_config == 1 && cfg->command != SLOT_CONFIG) { ykp_errno = YKP_EINVAL; - return 0; + goto out; } else if(target_config == 2 && cfg->command != SLOT_CONFIG2) { ykp_errno = YKP_EINVAL; - return 0; + goto out; } } @@ -307,11 +308,13 @@ int _ykp_json_import_cfg(YKP_CONFIG *cfg, const char *json, size_t len) { /* copy in the ykcore config again */ cfg->ykcore_config = ycfg; - - json_object_put(jobj); - return 1; + ret_code = 1; +out: + if(jobj) { + json_object_put(jobj); + } } ykp_errno = YKP_EINVAL; - return 0; + return ret_code; } -- 2.39.5