[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xen master] tools/xenstore: fix error handling of check_store()



commit fe9be76d880b1d43b9dca471f45af3fd380ecb00
Author:     Juergen Gross <jgross@xxxxxxxx>
AuthorDate: Fri Jan 21 14:12:19 2022 +0100
Commit:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
CommitDate: Fri Jan 21 15:34:46 2022 +0000

    tools/xenstore: fix error handling of check_store()
    
    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@xxxxxxxx>
    Reviewed-by: Anthony PERARD <anthony.perard@xxxxxxxxxx>
---
 tools/xenstore/xenstored_core.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c
index c386ae6129..91d3adccb1 100644
--- a/tools/xenstore/xenstored_core.c
+++ b/tools/xenstore/xenstored_core.c
@@ -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);
 }
 
--
generated by git-patchbot for /home/xen/git/xen.git#master



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.