summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_malloc.c
diff options
context:
space:
mode:
authorbp <bp@FreeBSD.org>2000-06-29 03:41:30 +0000
committerbp <bp@FreeBSD.org>2000-06-29 03:41:30 +0000
commit12d92ca4840d8a4774f880ce5fffc9e30b05d810 (patch)
tree6be0ff54f148965aebf646f04ffadd8c6bdf6a3b /sys/kern/kern_malloc.c
parent11a7e21e9c91061aa8b8e0790f26761e25a63b2f (diff)
downloadFreeBSD-src-12d92ca4840d8a4774f880ce5fffc9e30b05d810.zip
FreeBSD-src-12d92ca4840d8a4774f880ce5fffc9e30b05d810.tar.gz
If kernel compiled with INVARIANTS:
On unload, remove references from freelist to memory type defined by module. Print a warning if module defines and allocate its own memory type, but didn't free it all on unload. Reviewed by: peter
Diffstat (limited to 'sys/kern/kern_malloc.c')
-rw-r--r--sys/kern/kern_malloc.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c
index fe9459f..d228d8f 100644
--- a/sys/kern/kern_malloc.c
+++ b/sys/kern/kern_malloc.c
@@ -494,6 +494,12 @@ malloc_uninit(data)
{
struct malloc_type *type = (struct malloc_type *)data;
struct malloc_type *t;
+ struct kmembuckets *kbp;
+ struct freelist *freep;
+ long indx;
+#ifdef INVARIANTS
+ int s;
+#endif
if (type->ks_magic != M_MAGIC)
panic("malloc type lacks magic");
@@ -504,6 +510,24 @@ malloc_uninit(data)
if (type->ks_limit == 0)
panic("malloc_uninit on uninitialized type");
+#ifdef INVARIANTS
+ s = splmem();
+ for (indx = 0; indx < MINBUCKET + 16; indx++) {
+ kbp = bucket + indx;
+ freep = (struct freelist*)kbp->kb_next;
+ while (freep) {
+ if (freep->type == type)
+ freep->type = M_FREE;
+ freep = (struct freelist*)freep->next;
+ }
+ }
+ splx(s);
+
+ if (type->ks_memuse != 0)
+ printf("malloc_uninit: %ld bytes of '%s' still allocated\n",
+ type->ks_memuse, type->ks_shortdesc);
+#endif
+
if (type == kmemstatistics)
kmemstatistics = type->ks_next;
else {
OpenPOWER on IntegriCloud