diff options
-rw-r--r-- | sys/kern/kern_malloc.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c index 6073e9c..4b707aa 100644 --- a/sys/kern/kern_malloc.c +++ b/sys/kern/kern_malloc.c @@ -608,7 +608,10 @@ void malloc_uninit(void *data) { struct malloc_type_internal *mtip; + struct malloc_type_stats *mtsp; struct malloc_type *mtp, *temp; + long temp_allocs, temp_bytes; + int i; mtp = data; KASSERT(mtp->ks_handle != NULL, ("malloc_deregister: cookie NULL")); @@ -625,6 +628,24 @@ malloc_uninit(void *data) kmemstatistics = mtp->ks_next; kmemcount--; mtx_unlock(&malloc_mtx); + + /* + * Look for memory leaks. + */ + temp_allocs = temp_bytes = 0; + for (i = 0; i < MAXCPU; i++) { + mtsp = &mtip->mti_stats[i]; + temp_allocs += mtsp->mts_numallocs; + temp_allocs -= mtsp->mts_numfrees; + temp_bytes += mtsp->mts_memalloced; + temp_bytes -= mtsp->mts_memfreed; + } + if (temp_allocs > 0 || temp_bytes > 0) { + printf("Warning: memory type %s leaked memory on destroy " + "(%ld allocations, %ld bytes leaked).\n", mtp->ks_shortdesc, + temp_allocs, temp_bytes); + } + uma_zfree(mt_zone, mtip); } |