Skip to content

Commit 415e1b4

Browse files
Ryan MoellerRyan Moeller
authored andcommitted
FreeBSD: Fix memory leaks in kstats
Free the kstat object from the correct malloc zone if allocating data for a non-virtual kstat fails. Free the data allocated for non-virtual kstats when deleting the object. Signed-off-by: Ryan Moeller <[email protected]>
1 parent 1daad98 commit 415e1b4

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

module/os/freebsd/spl/spl_kstat.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ __kstat_create(const char *module, int instance, const char *name,
304304
} else {
305305
ksp->ks_data = kmem_zalloc(ksp->ks_data_size, KM_SLEEP);
306306
if (ksp->ks_data == NULL) {
307-
kmem_free(ksp, sizeof (*ksp));
307+
free(ksp, M_KSTAT);
308308
ksp = NULL;
309309
}
310310
}
@@ -509,6 +509,8 @@ kstat_delete(kstat_t *ksp)
509509
sysctl_ctx_free(&ksp->ks_sysctl_ctx);
510510
ksp->ks_lock = NULL;
511511
mutex_destroy(&ksp->ks_private_lock);
512+
if (!(ksp->ks_flags & KSTAT_FLAG_VIRTUAL))
513+
kmem_free(ksp->ks_data, ksp->ks_data_size);
512514
free(ksp, M_KSTAT);
513515
}
514516

0 commit comments

Comments
 (0)