tools/xenstore: fix error handling of check_store()
authorJuergen Gross <jgross@suse.com>
Fri, 21 Jan 2022 13:12:19 +0000 (14:12 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 21 Jan 2022 15:34:46 +0000 (15:34 +0000)
check_store() has an incomplete error handling: it doesn't check
whether "root" allocation succeeded, and it is leaking the memory of
"root" in case create_hashtable() fails.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Anthony PERARD <anthony.perard@citrix.com>
tools/xenstore/xenstored_core.c

index c386ae6129bdb73f720a5318235cf75f9f164876..91d3adccb1ad7350db993d529c0a6dac66e907f5 100644 (file)
@@ -2050,14 +2050,18 @@ static void clean_store(struct hashtable *reachable)
 
 void check_store(void)
 {
-       char * root = talloc_strdup(NULL, "/");
-       struct hashtable * reachable =
-               create_hashtable(16, hash_from_key_fn, keys_equal_fn);
-       if (!reachable) {
+       char *root = talloc_strdup(NULL, "/");
+       struct hashtable *reachable;
+
+       if (!root) {
                log("check_store: ENOMEM");
                return;
        }
+       reachable = create_hashtable(16, hash_from_key_fn, keys_equal_fn);
+       if (!reachable) {
+               log("check_store: ENOMEM");
+               goto out_root;
+       }
 
        log("Checking store ...");
        if (!check_store_(root, reachable) &&
@@ -2067,6 +2071,7 @@ void check_store(void)
 
        hashtable_destroy(reachable, 0 /* Don't free values (they are all
                                          (void *)1) */);
+ out_root:
        talloc_free(root);
 }