Fix zmo leak when zfs_sb_create fails

zfs_sb_create would normally takes ownership of zmo, and it will be freed in
zfs_sb_free. However, when zfs_sb_create fails we need to explicit free it.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Chunwei Chen <david.chen@osnexus.com>
Closes #5490
Closes #5496
This commit is contained in:
Chunwei Chen 2016-12-19 09:46:29 -08:00 committed by Brian Behlendorf
parent d425320ac8
commit 110470266d
1 changed files with 9 additions and 10 deletions

View File

@ -699,20 +699,18 @@ zfs_sb_create(const char *osname, zfs_mntopts_t *zmo, zfs_sb_t **zsbp)
zsb = kmem_zalloc(sizeof (zfs_sb_t), KM_SLEEP); zsb = kmem_zalloc(sizeof (zfs_sb_t), KM_SLEEP);
/*
* Optional temporary mount options, free'd in zfs_sb_free().
*/
zsb->z_mntopts = (zmo ? zmo : zfs_mntopts_alloc());
/* /*
* We claim to always be readonly so we can open snapshots; * We claim to always be readonly so we can open snapshots;
* other ZPL code will prevent us from writing to snapshots. * other ZPL code will prevent us from writing to snapshots.
*/ */
error = dmu_objset_own(osname, DMU_OST_ZFS, B_TRUE, zsb, &os); error = dmu_objset_own(osname, DMU_OST_ZFS, B_TRUE, zsb, &os);
if (error) { if (error)
kmem_free(zsb, sizeof (zfs_sb_t)); goto out_zmo;
return (error);
}
/*
* Optional temporary mount options, free'd in zfs_sb_free().
*/
zsb->z_mntopts = (zmo ? zmo : zfs_mntopts_alloc());
/* /*
* Initialize the zfs-specific filesystem structure. * Initialize the zfs-specific filesystem structure.
@ -840,8 +838,9 @@ zfs_sb_create(const char *osname, zfs_mntopts_t *zmo, zfs_sb_t **zsbp)
out: out:
dmu_objset_disown(os, zsb); dmu_objset_disown(os, zsb);
out_zmo:
*zsbp = NULL; *zsbp = NULL;
zfs_mntopts_free(zsb->z_mntopts);
kmem_free(zsb, sizeof (zfs_sb_t)); kmem_free(zsb, sizeof (zfs_sb_t));
return (error); return (error);
} }