vconf-compat: fix managing the list in keylist struct 68/44168/1
authorSuchang Woo <suchang.woo@samsung.com>
Fri, 17 Jul 2015 10:01:23 +0000 (19:01 +0900)
committerSuchang Woo <suchang.woo@samsung.com>
Fri, 17 Jul 2015 10:01:23 +0000 (19:01 +0900)
- Add codes to append keynode to the list
- Reset list after all the list elements are freed

Change-Id: Iba1726e86f20838ca3ad93eb562de37c1dafdee0
Signed-off-by: Suchang Woo <suchang.woo@samsung.com>
vconf-compat/vconf.c

index b0d97d7..f1a9c0f 100644 (file)
@@ -817,6 +817,8 @@ static struct _keynode_t *get_keynode(struct _keylist_t *keylist,
                return NULL;
        }
 
+       keylist->list = g_list_append(keylist->list, keynode);
+
        return keynode;
 }
 
@@ -900,14 +902,16 @@ EXPORT int vconf_keylist_add_str(keylist_t *keylist,
                return -1;
        }
 
-       keynode = get_keynode(keylist, keyname);
-       if (!keynode)
-               return -1;
-
        s = strdup(value);
        if (!s)
                return -1;
 
+       keynode = get_keynode(keylist, keyname);
+       if (!keynode) {
+               free(s);
+               return -1;
+       }
+
        if (keynode->type == VCONF_TYPE_STRING)
                free(keynode->value.s);
 
@@ -1060,6 +1064,7 @@ EXPORT int vconf_get(keylist_t *keylist,
        }
 
        g_list_free_full(keylist->list, (GDestroyNotify)free_keynode);
+       keylist->list = NULL;
 
        for (i = 0; i < len; i++) {
                struct _keynode_t *keynode;