From 549cf0169041b2234865474184b34f315ba432dd Mon Sep 17 00:00:00 2001 From: grog Date: Mon, 5 Apr 1999 04:02:09 +0000 Subject: free_vinum: Clean out bdevsw entry before unloading kld. Repeatedly-tripped-over-by: Vallo Kallaste When VINUMDEBUG is set, free any memory found still allocated. Only log errors if DEBUG_EXITFREE is set. --- sys/dev/vinum/vinum.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'sys') diff --git a/sys/dev/vinum/vinum.c b/sys/dev/vinum/vinum.c index d9621f9..4005124 100644 --- a/sys/dev/vinum/vinum.c +++ b/sys/dev/vinum/vinum.c @@ -213,16 +213,31 @@ vinum_modevent(module_t mod, modeventtype_t type, void *unused) #ifdef VINUMDEBUG if (total_malloced) { int i; - - for (i = 0; i < malloccount; i++) - log(LOG_WARNING, - "vinum: exiting with %d bytes malloced from %s:%d\n", - malloced[i].size, - malloced[i].file, - malloced[i].line); + int *poke; + + for (i = 0; i < malloccount; i++) { + if (debug & DEBUG_EXITFREE) /* want to hear about them */ + log(LOG_WARNING, + "vinum: exiting with %d bytes malloced from %s:%d\n", + malloced[i].size, + malloced[i].file, + malloced[i].line); +#ifdef INVARIANTS + poke = &((int *) malloced[i].address) + [malloced[i].size / (2 * sizeof(int))]; /* middle of the area */ + if (*poke == 0xdeadc0de) /* already freed */ + log(LOG_ERR, + "vinum: exiting with malloc table inconsistency at %p from %s:%d\n", + malloced[i].address, + malloced[i].file, + malloced[i].line); +#endif + Free(malloced[i].address); + } } #endif cdevsw[CDEV_MAJOR] = NULL; /* no cdevsw any more */ + bdevsw[BDEV_MAJOR] = NULL; /* nor bdevsw */ log(LOG_INFO, "vinum: unloaded\n"); /* tell the world */ return 0; default: -- cgit v1.1