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
This commit is contained in:
bp 2000-06-29 03:41:30 +00:00
parent 11a7e21e9c
commit 12d92ca484

View File

@ -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 {