libzfs: mount: zfs_unshare: don't reallocate mountpoint

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes #13165
This commit is contained in:
наб 2022-02-28 16:55:16 +01:00 committed by Brian Behlendorf
parent b4d9a82f62
commit 5b14feec06
1 changed files with 7 additions and 15 deletions

View File

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