]> git.proxmox.com Git - mirror_zfs.git/commitdiff
nvlist leaked in zpool_find_config()
authorMatthew Ahrens <mahrens@delphix.com>
Wed, 23 Dec 2020 17:52:24 +0000 (09:52 -0800)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Tue, 5 Jan 2021 18:31:47 +0000 (10:31 -0800)
In `zpool_find_config()`, the `pools` nvlist is leaked.  Part of it (a
sub-nvlist) is returned in `*configp`, but the callers also leak that.

Additionally, in `zdb.c:main()`, the `searchdirs` is leaked.

The leaks were detected by ASAN (`configure --enable-asan`).

This commit resolves the leaks.

Reviewed-by: Igor Kozhukhov <igor@dilos.org>
Reviewed-by: Ryan Moeller <ryan@iXsystems.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Matthew Ahrens <mahrens@delphix.com>
Closes #11396

cmd/zdb/zdb.c
cmd/zhack/zhack.c
cmd/ztest/ztest.c
lib/libzutil/zutil_import.c

index 376b24db1eec3cd6b55e2f9d41154400af4647ec..c16492c53efc3cfa00ba12e9e7abe96fa8ef6fb2 100644 (file)
@@ -8429,6 +8429,11 @@ main(int argc, char **argv)
                }
        }
 
+       if (searchdirs != NULL) {
+               umem_free(searchdirs, nsearch * sizeof (char *));
+               searchdirs = NULL;
+       }
+
        /*
         * import_checkpointed_state makes the assumption that the
         * target pool that we pass it is already part of the spa
@@ -8447,6 +8452,11 @@ main(int argc, char **argv)
                        target = checkpoint_target;
        }
 
+       if (cfg != NULL) {
+               nvlist_free(cfg);
+               cfg = NULL;
+       }
+
        if (target_pool != target)
                free(target_pool);
 
index 4d958fe4365a90096938e90142918e507727d898..08263120c7c441cf265f07f0a16dee4a9d18129c 100644 (file)
@@ -150,6 +150,7 @@ zhack_import(char *target, boolean_t readonly)
        zfeature_checks_disable = B_TRUE;
        error = spa_import(target, config, props,
            (readonly ?  ZFS_IMPORT_SKIP_MMP : ZFS_IMPORT_NORMAL));
+       fnvlist_free(config);
        zfeature_checks_disable = B_FALSE;
        if (error == EEXIST)
                error = 0;
index 31205a5bf8cf7c986116e07e4636c22ea5d03daf..4e1be4dd737f4d62c7be4e2f2345e28d60006248 100644 (file)
@@ -7016,6 +7016,7 @@ ztest_import_impl(ztest_shared_t *zs)
        VERIFY0(zpool_find_config(NULL, ztest_opts.zo_pool, &cfg, &args,
            &libzpool_config_ops));
        VERIFY0(spa_import(ztest_opts.zo_pool, cfg, NULL, flags));
+       fnvlist_free(cfg);
 }
 
 /*
index b8cdc118b263c9e424c67a7f003202ee76bf5a8f..3a1827294502e533b1c26e6422cec4bc4fdd483a 100644 (file)
@@ -1539,7 +1539,7 @@ zpool_find_config(void *hdl, const char *target, nvlist_t **configp,
        nvlist_t *pools;
        nvlist_t *match = NULL;
        nvlist_t *config = NULL;
-       char *name = NULL, *sepp = NULL;
+       char *sepp = NULL;
        char sep = '\0';
        int count = 0;
        char *targetdup = strdup(target);
@@ -1563,11 +1563,11 @@ zpool_find_config(void *hdl, const char *target, nvlist_t **configp,
                                        /* multiple matches found */
                                        continue;
                                } else {
-                                       match = config;
-                                       name = nvpair_name(elem);
+                                       match = fnvlist_dup(config);
                                }
                        }
                }
+               fnvlist_free(pools);
        }
 
        if (count == 0) {
@@ -1577,6 +1577,7 @@ zpool_find_config(void *hdl, const char *target, nvlist_t **configp,
 
        if (count > 1) {
                free(targetdup);
+               fnvlist_free(match);
                return (EINVAL);
        }