]> err.no Git - yubikey-personalization/commitdiff
make sure json objects are released on error conditions
authorKlas Lindfors <klas@yubico.com>
Thu, 25 Apr 2013 08:57:14 +0000 (10:57 +0200)
committerKlas Lindfors <klas@yubico.com>
Thu, 25 Apr 2013 08:59:38 +0000 (10:59 +0200)
ykpers-json.c

index 1c19e3ea1dbf52ce6799a485f211bd5aaf91c1c9..5425f756e27664f66d20cf71f1a5409e56e2b142 100644 (file)
@@ -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;
 }