From 6d4210052be6c63032d693aa487f84955b0dae44 Mon Sep 17 00:00:00 2001 From: BearBabyLiu Date: Thu, 3 Nov 2016 03:34:10 +0800 Subject: [PATCH] Fix dsl_prop_get_all_dsl() memory leak On error dsl_prop_get_all_ds() does not free the nvlist it allocates. This behavior may have been intentional when originally written but is atypical and often confusing. Since no callers rely on this behavior the function has been updated to always free the nvlist on error. Reviewed-by: Brian Behlendorf Signed-off-by: BearBabyLiu Closes #5320 --- module/zfs/dsl_prop.c | 4 ++++ module/zfs/zfs_ioctl.c | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/module/zfs/dsl_prop.c b/module/zfs/dsl_prop.c index 24836000f3..ece1e19754 100644 --- a/module/zfs/dsl_prop.c +++ b/module/zfs/dsl_prop.c @@ -1127,6 +1127,10 @@ dsl_prop_get_all_ds(dsl_dataset_t *ds, nvlist_t **nvp, break; } out: + if (err) { + nvlist_free(*nvp); + *nvp = NULL; + } return (err); } diff --git a/module/zfs/zfs_ioctl.c b/module/zfs/zfs_ioctl.c index e3166a40e9..0a8d260e68 100644 --- a/module/zfs/zfs_ioctl.c +++ b/module/zfs/zfs_ioctl.c @@ -2033,8 +2033,10 @@ zfs_ioc_objset_stats_impl(zfs_cmd_t *zc, objset_t *os) if (!zc->zc_objset_stats.dds_inconsistent && dmu_objset_type(os) == DMU_OST_ZVOL) { error = zvol_get_stats(os, nv); - if (error == EIO) + if (error == EIO) { + nvlist_free(nv); return (error); + } VERIFY0(error); } if (error == 0)