From 110470266d6d443d21096ca82bd16d74685675ac Mon Sep 17 00:00:00 2001 From: Chunwei Chen Date: Mon, 19 Dec 2016 09:46:29 -0800 Subject: [PATCH] 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 Signed-off-by: Chunwei Chen Closes #5490 Closes #5496 --- module/zfs/zfs_vfsops.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/module/zfs/zfs_vfsops.c b/module/zfs/zfs_vfsops.c index 3dc162250b..d7786f6b66 100644 --- a/module/zfs/zfs_vfsops.c +++ b/module/zfs/zfs_vfsops.c @@ -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); + /* + * 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; * other ZPL code will prevent us from writing to snapshots. */ error = dmu_objset_own(osname, DMU_OST_ZFS, B_TRUE, zsb, &os); - if (error) { - kmem_free(zsb, sizeof (zfs_sb_t)); - return (error); - } - - /* - * Optional temporary mount options, free'd in zfs_sb_free(). - */ - zsb->z_mntopts = (zmo ? zmo : zfs_mntopts_alloc()); + if (error) + goto out_zmo; /* * 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: dmu_objset_disown(os, zsb); +out_zmo: *zsbp = NULL; - + zfs_mntopts_free(zsb->z_mntopts); kmem_free(zsb, sizeof (zfs_sb_t)); return (error); }