Detect memory leaks when memory type is being destroyed.
This is very helpful for detecting kernel modules memory leaks on unload. Discussed and reviewed by: rwatson
This commit is contained in:
parent
9d14a9a235
commit
2a143d5bf5
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=152017
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user