From: Michael Brown Date: Mon, 30 Apr 2012 19:33:23 +0000 (+0100) Subject: [malloc] Discard all cached data on shutdown X-Git-Tag: v1.20.1~1817 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=df2773193ec1aaf7b53d3e51c6431cdb2ee313b9;p=thirdparty%2Fipxe.git [malloc] Discard all cached data on shutdown Allow detection of genuine memory leaks by ensuring that all cached data is freed on shutdown. Signed-off-by: Michael Brown --- diff --git a/src/core/malloc.c b/src/core/malloc.c index d694f5559..32fd5fc0e 100644 --- a/src/core/malloc.c +++ b/src/core/malloc.c @@ -144,6 +144,18 @@ static unsigned int discard_cache ( void ) { return discarded; } +/** + * Discard all cached data + * + */ +static void discard_all_cache ( void ) { + unsigned int discarded; + + do { + discarded = discard_cache(); + } while ( discarded ); +} + /** * Allocate a memory block * @@ -458,6 +470,19 @@ struct init_fn heap_init_fn __init_fn ( INIT_EARLY ) = { .initialise = init_heap, }; +/** + * Discard all cached data on shutdown + * + */ +static void shutdown_cache ( int booting __unused ) { + discard_all_cache(); +} + +/** Memory allocator shutdown function */ +struct startup_fn heap_startup_fn __startup_fn ( STARTUP_EARLY ) = { + .shutdown = shutdown_cache, +}; + #if 0 #include /**