Skip to content

Commit

Permalink
nvlist leaked in zpool_find_config()
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Ryan Moeller <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Matthew Ahrens <[email protected]>
Closes openzfs#11396
  • Loading branch information
ahrens authored and behlendorf committed Dec 28, 2020
1 parent 40ab927 commit b6722b8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
10 changes: 10 additions & 0 deletions cmd/zdb/zdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -8435,6 +8435,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
Expand All @@ -8453,6 +8458,11 @@ main(int argc, char **argv)
target = checkpoint_target;
}

if (cfg != NULL) {
nvlist_free(cfg);
cfg = NULL;
}

if (target_pool != target)
free(target_pool);

Expand Down
1 change: 1 addition & 0 deletions cmd/zhack/zhack.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions cmd/ztest/ztest.c
Original file line number Diff line number Diff line change
Expand Up @@ -7153,6 +7153,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);
}

/*
Expand Down
7 changes: 4 additions & 3 deletions lib/libzutil/zutil_import.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand All @@ -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);
}

Expand Down

0 comments on commit b6722b8

Please sign in to comment.