mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 02:27:36 +03:00
Fix memleak in zfs_do_* and zpool_do_*
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: luozhengzheng <luo.zhengzheng@zte.com.cn> Closes #5056
This commit is contained in:
committed by
Brian Behlendorf
parent
e33da554c5
commit
a425f5bff9
+23
-5
@@ -1296,6 +1296,7 @@ zpool_do_destroy(int argc, char **argv)
|
||||
if (zpool_disable_datasets(zhp, force) != 0) {
|
||||
(void) fprintf(stderr, gettext("could not destroy '%s': "
|
||||
"could not unmount datasets\n"), zpool_get_name(zhp));
|
||||
zpool_close(zhp);
|
||||
return (1);
|
||||
}
|
||||
|
||||
@@ -2343,6 +2344,7 @@ zpool_do_import(int argc, char **argv)
|
||||
if (searchdirs != NULL)
|
||||
free(searchdirs);
|
||||
|
||||
nvlist_free(props);
|
||||
nvlist_free(policy);
|
||||
return (1);
|
||||
}
|
||||
@@ -2449,6 +2451,8 @@ zpool_do_import(int argc, char **argv)
|
||||
if (envdup != NULL)
|
||||
free(envdup);
|
||||
nvlist_free(policy);
|
||||
nvlist_free(pools);
|
||||
nvlist_free(props);
|
||||
return (1);
|
||||
}
|
||||
|
||||
@@ -4749,13 +4753,16 @@ zpool_do_attach_or_replace(int argc, char **argv, int replacing)
|
||||
usage(B_FALSE);
|
||||
}
|
||||
|
||||
if ((zhp = zpool_open(g_zfs, poolname)) == NULL)
|
||||
if ((zhp = zpool_open(g_zfs, poolname)) == NULL) {
|
||||
nvlist_free(props);
|
||||
return (1);
|
||||
}
|
||||
|
||||
if (zpool_get_config(zhp, NULL) == NULL) {
|
||||
(void) fprintf(stderr, gettext("pool '%s' is unavailable\n"),
|
||||
poolname);
|
||||
zpool_close(zhp);
|
||||
nvlist_free(props);
|
||||
return (1);
|
||||
}
|
||||
|
||||
@@ -4763,11 +4770,13 @@ zpool_do_attach_or_replace(int argc, char **argv, int replacing)
|
||||
argc, argv);
|
||||
if (nvroot == NULL) {
|
||||
zpool_close(zhp);
|
||||
nvlist_free(props);
|
||||
return (1);
|
||||
}
|
||||
|
||||
ret = zpool_vdev_attach(zhp, old_disk, new_disk, nvroot, replacing);
|
||||
|
||||
nvlist_free(props);
|
||||
nvlist_free(nvroot);
|
||||
zpool_close(zhp);
|
||||
|
||||
@@ -4973,8 +4982,10 @@ zpool_do_split(int argc, char **argv)
|
||||
argc -= 2;
|
||||
argv += 2;
|
||||
|
||||
if ((zhp = zpool_open(g_zfs, srcpool)) == NULL)
|
||||
if ((zhp = zpool_open(g_zfs, srcpool)) == NULL) {
|
||||
nvlist_free(props);
|
||||
return (1);
|
||||
}
|
||||
|
||||
config = split_mirror_vdev(zhp, newpool, props, flags, argc, argv);
|
||||
if (config == NULL) {
|
||||
@@ -4986,20 +4997,25 @@ zpool_do_split(int argc, char **argv)
|
||||
print_vdev_tree(NULL, newpool, config, 0, B_FALSE,
|
||||
flags.name_flags);
|
||||
}
|
||||
nvlist_free(config);
|
||||
}
|
||||
|
||||
zpool_close(zhp);
|
||||
|
||||
if (ret != 0 || flags.dryrun || !flags.import)
|
||||
if (ret != 0 || flags.dryrun || !flags.import) {
|
||||
nvlist_free(config);
|
||||
nvlist_free(props);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
/*
|
||||
* The split was successful. Now we need to open the new
|
||||
* pool and import it.
|
||||
*/
|
||||
if ((zhp = zpool_open_canfail(g_zfs, newpool)) == NULL)
|
||||
if ((zhp = zpool_open_canfail(g_zfs, newpool)) == NULL) {
|
||||
nvlist_free(config);
|
||||
nvlist_free(props);
|
||||
return (1);
|
||||
}
|
||||
if (zpool_get_state(zhp) != POOL_STATE_UNAVAIL &&
|
||||
zpool_enable_datasets(zhp, mntopts, 0) != 0) {
|
||||
ret = 1;
|
||||
@@ -5009,6 +5025,8 @@ zpool_do_split(int argc, char **argv)
|
||||
"different altroot\n"), "zpool import");
|
||||
}
|
||||
zpool_close(zhp);
|
||||
nvlist_free(config);
|
||||
nvlist_free(props);
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user