diff options
author | Tom Caputi <[email protected]> | 2019-03-14 21:14:36 -0400 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2019-03-14 18:14:36 -0700 |
commit | 04a3b0796c622201e2cde6b7288043f90da1ba33 (patch) | |
tree | 7ce9e6c7477f0e25bf149fbc440206dcae267971 | |
parent | c742bf1e68be582fb2db029e38768f8450d2609d (diff) |
Fix memory leaks in zfsvfs_create_impl()
This patch simply fixes some small memory leaks that can happen
during error handling in zfsvfs_create_impl(). If the function
fails, it frees all the memory / references it created.
Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: Tony Hutter <[email protected]>
Signed-off-by: Tom Caputi <[email protected]>
Closes #8490
-rw-r--r-- | module/zfs/zfs_vfsops.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/module/zfs/zfs_vfsops.c b/module/zfs/zfs_vfsops.c index cdc1bc707..781708ba9 100644 --- a/module/zfs/zfs_vfsops.c +++ b/module/zfs/zfs_vfsops.c @@ -1035,14 +1035,6 @@ zfsvfs_init(zfsvfs_t *zfsvfs, objset_t *os) zfsvfs->z_xattr_sa = B_TRUE; } - error = sa_setup(os, sa_obj, zfs_attr_table, ZPL_END, - &zfsvfs->z_attr_table); - if (error != 0) - return (error); - - if (zfsvfs->z_version >= ZPL_VERSION_SA) - sa_register_update_callback(os, zfs_sa_upgrade); - error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_ROOT_OBJ, 8, 1, &zfsvfs->z_root); if (error != 0) @@ -1116,6 +1108,14 @@ zfsvfs_init(zfsvfs_t *zfsvfs, objset_t *os) else if (error != 0) return (error); + error = sa_setup(os, sa_obj, zfs_attr_table, ZPL_END, + &zfsvfs->z_attr_table); + if (error != 0) + return (error); + + if (zfsvfs->z_version >= ZPL_VERSION_SA) + sa_register_update_callback(os, zfs_sa_upgrade); + return (0); } @@ -1142,6 +1142,11 @@ zfsvfs_create(const char *osname, boolean_t readonly, zfsvfs_t **zfvp) return (error); } + +/* + * Note: zfsvfs is assumed to be malloc'd, and will be freed by this function + * on a failure. Do not pass in a statically allocated zfsvfs. + */ int zfsvfs_create_impl(zfsvfs_t **zfvp, zfsvfs_t *zfsvfs, objset_t *os) { @@ -1174,7 +1179,7 @@ zfsvfs_create_impl(zfsvfs_t **zfvp, zfsvfs_t *zfsvfs, objset_t *os) error = zfsvfs_init(zfsvfs, os); if (error != 0) { *zfvp = NULL; - kmem_free(zfsvfs, sizeof (zfsvfs_t)); + zfsvfs_free(zfsvfs); return (error); } |