diff options
author | luozhengzheng <[email protected]> | 2016-09-01 10:23:10 +0800 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2016-09-12 13:02:47 -0700 |
commit | a425f5bff92f2db78f588543f49ce3abbd98a7f9 (patch) | |
tree | acc7725382bcb0267482faaea0d7f6faa47624a9 /cmd/zfs | |
parent | e33da554c5daf0103b093f44ab5b90ad6c064c3f (diff) |
Fix memleak in zfs_do_* and zpool_do_*
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: luozhengzheng <[email protected]>
Closes #5056
Diffstat (limited to 'cmd/zfs')
-rw-r--r-- | cmd/zfs/zfs_main.c | 45 |
1 files changed, 35 insertions, 10 deletions
diff --git a/cmd/zfs/zfs_main.c b/cmd/zfs/zfs_main.c index 8a8f56af9..063ee7c54 100644 --- a/cmd/zfs/zfs_main.c +++ b/cmd/zfs/zfs_main.c @@ -659,8 +659,10 @@ zfs_do_clone(int argc, char **argv) while ((c = getopt(argc, argv, "o:p")) != -1) { switch (c) { case 'o': - if (parseprop(props, optarg) != 0) + if (parseprop(props, optarg) != 0) { + nvlist_free(props); return (1); + } break; case 'p': parents = B_TRUE; @@ -692,8 +694,10 @@ zfs_do_clone(int argc, char **argv) } /* open the source dataset */ - if ((zhp = zfs_open(g_zfs, argv[0], ZFS_TYPE_SNAPSHOT)) == NULL) + if ((zhp = zfs_open(g_zfs, argv[0], ZFS_TYPE_SNAPSHOT)) == NULL) { + nvlist_free(props); return (1); + } if (parents && zfs_name_valid(argv[1], ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME)) { @@ -703,10 +707,16 @@ zfs_do_clone(int argc, char **argv) * complain. */ if (zfs_dataset_exists(g_zfs, argv[1], ZFS_TYPE_FILESYSTEM | - ZFS_TYPE_VOLUME)) + ZFS_TYPE_VOLUME)) { + zfs_close(zhp); + nvlist_free(props); return (0); - if (zfs_create_ancestors(g_zfs, argv[1]) != 0) + } + if (zfs_create_ancestors(g_zfs, argv[1]) != 0) { + zfs_close(zhp); + nvlist_free(props); return (1); + } } /* pass to libzfs */ @@ -1280,8 +1290,10 @@ zfs_do_destroy(int argc, char **argv) *at = '\0'; zhp = zfs_open(g_zfs, argv[0], ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME); - if (zhp == NULL) + if (zhp == NULL) { + nvlist_free(cb.cb_nvl); return (1); + } cb.cb_snapspec = at + 1; if (gather_snapshots(zfs_handle_dup(zhp), &cb) != 0 || @@ -1370,7 +1382,7 @@ zfs_do_destroy(int argc, char **argv) "cannot destroy bookmark"); } - nvlist_free(cb.cb_nvl); + nvlist_free(nvl); return (err); } else { @@ -3645,8 +3657,11 @@ zfs_do_snapshot(int argc, char **argv) while ((c = getopt(argc, argv, "ro:")) != -1) { switch (c) { case 'o': - if (parseprop(props, optarg) != 0) + if (parseprop(props, optarg) != 0) { + nvlist_free(sd.sd_nvl); + nvlist_free(props); return (1); + } break; case 'r': sd.sd_recursive = B_TRUE; @@ -3937,8 +3952,10 @@ zfs_do_receive(int argc, char **argv) while ((c = getopt(argc, argv, ":o:denuvFsA")) != -1) { switch (c) { case 'o': - if (parseprop(props, optarg) != 0) + if (parseprop(props, optarg) != 0) { + nvlist_free(props); return (1); + } break; case 'd': flags.isprefix = B_TRUE; @@ -4012,9 +4029,12 @@ zfs_do_receive(int argc, char **argv) ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME)) { zfs_handle_t *zhp = zfs_open(g_zfs, namebuf, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME); - if (zhp == NULL) + if (zhp == NULL) { + nvlist_free(props); return (1); + } err = zfs_destroy(zhp, B_FALSE); + zfs_close(zhp); } else { zfs_handle_t *zhp = zfs_open(g_zfs, argv[0], ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME); @@ -4027,11 +4047,14 @@ zfs_do_receive(int argc, char **argv) gettext("'%s' does not have any " "resumable receive state to abort\n"), argv[0]); + nvlist_free(props); + zfs_close(zhp); return (1); } err = zfs_destroy(zhp, B_FALSE); + zfs_close(zhp); } - + nvlist_free(props); return (err != 0); } @@ -4040,9 +4063,11 @@ zfs_do_receive(int argc, char **argv) gettext("Error: Backup stream can not be read " "from a terminal.\n" "You must redirect standard input.\n")); + nvlist_free(props); return (1); } err = zfs_receive(g_zfs, argv[0], props, &flags, STDIN_FILENO, NULL); + nvlist_free(props); return (err != 0); } |