Skip to content

Commit a184921

Browse files
Ryan MoellerRyan Moeller
authored andcommitted
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. Signed-off-by: Ryan Moeller <[email protected]>
1 parent 1daad98 commit a184921

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

module/os/freebsd/spl/spl_kstat.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -299,15 +299,10 @@ __kstat_create(const char *module, int instance, const char *name,
299299
panic("Undefined kstat type %d\n", ksp->ks_type);
300300
}
301301

302-
if (ksp->ks_flags & KSTAT_FLAG_VIRTUAL) {
302+
if (ksp->ks_flags & KSTAT_FLAG_VIRTUAL)
303303
ksp->ks_data = NULL;
304-
} else {
304+
else
305305
ksp->ks_data = kmem_zalloc(ksp->ks_data_size, KM_SLEEP);
306-
if (ksp->ks_data == NULL) {
307-
kmem_free(ksp, sizeof (*ksp));
308-
ksp = NULL;
309-
}
310-
}
311306

312307
/*
313308
* Some kstats use a module name like "zfs/poolname" to distinguish a
@@ -509,6 +504,8 @@ kstat_delete(kstat_t *ksp)
509504
sysctl_ctx_free(&ksp->ks_sysctl_ctx);
510505
ksp->ks_lock = NULL;
511506
mutex_destroy(&ksp->ks_private_lock);
507+
if (!(ksp->ks_flags & KSTAT_FLAG_VIRTUAL))
508+
kmem_free(ksp->ks_data, ksp->ks_data_size);
512509
free(ksp, M_KSTAT);
513510
}
514511

0 commit comments

Comments
 (0)