]> git.proxmox.com Git - mirror_zfs.git/commitdiff
libzfs: mount: zfs_unshare: don't reallocate mountpoint
authorнаб <nabijaczleweli@nabijaczleweli.xyz>
Mon, 28 Feb 2022 15:55:16 +0000 (16:55 +0100)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Thu, 12 May 2022 16:26:47 +0000 (09:26 -0700)
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes #13165

lib/libzfs/libzfs_mount.c

index 77837a3b0f36d20c2cad1f3e625071bf712d42c4..d007441f8a8afebf9aac66614831b98c4f894e3c 100644 (file)
@@ -797,36 +797,28 @@ zfs_unshare(zfs_handle_t *zhp, const char *mountpoint,
 {
        libzfs_handle_t *hdl = zhp->zfs_hdl;
        struct mnttab entry;
-       char *mntpt = NULL;
+       const char *mntpt = NULL;
 
        if (proto == NULL)
                proto = share_all_proto;
 
        /* check to see if need to unmount the filesystem */
        if (mountpoint != NULL)
-               mntpt = zfs_strdup(hdl, mountpoint);
+               mntpt = mountpoint;
 
        if (mountpoint != NULL || ((zfs_get_type(zhp) == ZFS_TYPE_FILESYSTEM) &&
            libzfs_mnttab_find(hdl, zfs_get_name(zhp), &entry) == 0)) {
 
                if (mountpoint == NULL)
-                       mntpt = zfs_strdup(zhp->zfs_hdl, entry.mnt_mountp);
+                       mntpt = entry.mnt_mountp;
 
                for (const enum sa_protocol *curr_proto = proto;
-                   *curr_proto != SA_NO_PROTOCOL; curr_proto++) {
-
-                       if (sa_is_shared(mntpt, *curr_proto)) {
-                               if (unshare_one(hdl, zhp->zfs_name,
-                                   mntpt, *curr_proto) != 0) {
-                                       if (mntpt != NULL)
-                                               free(mntpt);
+                   *curr_proto != SA_NO_PROTOCOL; curr_proto++)
+                       if (sa_is_shared(mntpt, *curr_proto) &&
+                           unshare_one(hdl, zhp->zfs_name,
+                           mntpt, *curr_proto) != 0)
                                        return (-1);
-                               }
-                       }
-               }
        }
-       if (mntpt != NULL)
-               free(mntpt);
 
        return (0);
 }