diff options
author | Chunwei Chen <[email protected]> | 2016-12-19 09:46:29 -0800 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2016-12-19 09:46:29 -0800 |
commit | 6c01a4af2b5466fbdceba7304fa8b0dfb0dac839 (patch) | |
tree | be0fce29c164bb4f75673306796529c66d25d511 | |
parent | 1528bfdb148b44eaa0522109fee1ab61f4f3214b (diff) |
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 <[email protected]>
Signed-off-by: Chunwei Chen <[email protected]>
Closes #5490
Closes #5496
-rw-r--r-- | module/zfs/zfs_vfsops.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/module/zfs/zfs_vfsops.c b/module/zfs/zfs_vfsops.c index 1c3dccdca..3c76cfe6f 100644 --- a/module/zfs/zfs_vfsops.c +++ b/module/zfs/zfs_vfsops.c @@ -744,19 +744,17 @@ zfs_sb_create(const char *osname, zfs_mntopts_t *zmo, zfs_sb_t **zsbp) zsb = kmem_zalloc(sizeof (zfs_sb_t), KM_SLEEP); /* - * We claim to always be readonly so we can open snapshots; - * other ZPL code will prevent us from writing to snapshots. + * Optional temporary mount options, free'd in zfs_sb_free(). */ - error = dmu_objset_own(osname, DMU_OST_ZFS, B_TRUE, zsb, &os); - if (error) { - kmem_free(zsb, sizeof (zfs_sb_t)); - return (error); - } + zsb->z_mntopts = (zmo ? zmo : zfs_mntopts_alloc()); /* - * Optional temporary mount options, free'd in zfs_sb_free(). + * We claim to always be readonly so we can open snapshots; + * other ZPL code will prevent us from writing to snapshots. */ - zsb->z_mntopts = (zmo ? zmo : zfs_mntopts_alloc()); + error = dmu_objset_own(osname, DMU_OST_ZFS, B_TRUE, zsb, &os); + if (error) + goto out_zmo; /* * Initialize the zfs-specific filesystem structure. @@ -896,8 +894,9 @@ zfs_sb_create(const char *osname, zfs_mntopts_t *zmo, zfs_sb_t **zsbp) out: dmu_objset_disown(os, zsb); +out_zmo: *zsbp = NULL; - + zfs_mntopts_free(zsb->z_mntopts); kmem_free(zsb, sizeof (zfs_sb_t)); return (error); } |