summaryrefslogtreecommitdiffstats
path: root/lib/libzfs/libzfs_mount.c
diff options
context:
space:
mode:
authorcao <[email protected]>2016-08-31 18:35:52 +0800
committerBrian Behlendorf <[email protected]>2016-09-01 11:39:45 -0700
commit2d96d7aa56ea4a95206478474b2244be67a71853 (patch)
treeedcf007959e878bbfdff5fbacb95c8f260036af4 /lib/libzfs/libzfs_mount.c
parentee36c709c3d5f7040e1bd11f5c75318aa03e789f (diff)
Fix zfs_unmount() and zfs_unshare_proto() leaks
Always free mnpt memory on failure in the zfs_unmount() function. In the zfs_unshare_proto() function mountpoint is a const and should not be assigned. Signed-off-by: cao.xuewen <[email protected]> Signed-off-by: Brian Behlendorf <[email protected]> Closes #5054
Diffstat (limited to 'lib/libzfs/libzfs_mount.c')
-rw-r--r--lib/libzfs/libzfs_mount.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/libzfs/libzfs_mount.c b/lib/libzfs/libzfs_mount.c
index dfb748fc5..8c7f32638 100644
--- a/lib/libzfs/libzfs_mount.c
+++ b/lib/libzfs/libzfs_mount.c
@@ -564,8 +564,10 @@ zfs_unmount(zfs_handle_t *zhp, const char *mountpoint, int flags)
/*
* Unshare and unmount the filesystem
*/
- if (zfs_unshare_proto(zhp, mntpt, share_all_proto) != 0)
+ if (zfs_unshare_proto(zhp, mntpt, share_all_proto) != 0) {
+ free(mntpt);
return (-1);
+ }
if (unmount_one(hdl, mntpt, flags) != 0) {
free(mntpt);
@@ -904,7 +906,7 @@ zfs_unshare_proto(zfs_handle_t *zhp, const char *mountpoint,
/* check to see if need to unmount the filesystem */
if (mountpoint != NULL)
- mountpoint = mntpt = zfs_strdup(hdl, mountpoint);
+ mntpt = zfs_strdup(hdl, mountpoint);
if (mountpoint != NULL || ((zfs_get_type(zhp) == ZFS_TYPE_FILESYSTEM) &&
libzfs_mnttab_find(hdl, zfs_get_name(zhp), &entry) == 0)) {
@@ -918,7 +920,7 @@ zfs_unshare_proto(zfs_handle_t *zhp, const char *mountpoint,
if (is_shared(hdl, mntpt, *curr_proto) &&
unshare_one(hdl, zhp->zfs_name,
- mntpt, *curr_proto) != 0) {
+ mntpt, *curr_proto) != 0) {
if (mntpt != NULL)
free(mntpt);
return (-1);