aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyan Moeller <[email protected]>2021-03-18 00:55:18 -0400
committerGitHub <[email protected]>2021-03-17 21:55:18 -0700
commitec3e4c6784485beca965ae3ebdeea948dd4739f3 (patch)
treee1056d9d952647aaa30587f83199f39bfe36cc76
parent1daad98176d18a785d116d9666dadc866f631f98 (diff)
FreeBSD: Fix memory leaks in kstats
Don't handle (incorrectly) kmem_zalloc() failure. With KM_SLEEP, will never return NULL. Free the data allocated for non-virtual kstats when deleting the object. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Signed-off-by: Ryan Moeller <[email protected]> Closes #11767
-rw-r--r--module/os/freebsd/spl/spl_kstat.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/module/os/freebsd/spl/spl_kstat.c b/module/os/freebsd/spl/spl_kstat.c
index 6bdef466c..43ce35829 100644
--- a/module/os/freebsd/spl/spl_kstat.c
+++ b/module/os/freebsd/spl/spl_kstat.c
@@ -299,15 +299,10 @@ __kstat_create(const char *module, int instance, const char *name,
panic("Undefined kstat type %d\n", ksp->ks_type);
}
- if (ksp->ks_flags & KSTAT_FLAG_VIRTUAL) {
+ if (ksp->ks_flags & KSTAT_FLAG_VIRTUAL)
ksp->ks_data = NULL;
- } else {
+ else
ksp->ks_data = kmem_zalloc(ksp->ks_data_size, KM_SLEEP);
- if (ksp->ks_data == NULL) {
- kmem_free(ksp, sizeof (*ksp));
- ksp = NULL;
- }
- }
/*
* Some kstats use a module name like "zfs/poolname" to distinguish a
@@ -509,6 +504,8 @@ kstat_delete(kstat_t *ksp)
sysctl_ctx_free(&ksp->ks_sysctl_ctx);
ksp->ks_lock = NULL;
mutex_destroy(&ksp->ks_private_lock);
+ if (!(ksp->ks_flags & KSTAT_FLAG_VIRTUAL))
+ kmem_free(ksp->ks_data, ksp->ks_data_size);
free(ksp, M_KSTAT);
}