diff options
author | Michael Brown | 2012-04-30 21:33:23 +0200 |
---|---|---|
committer | Michael Brown | 2012-05-04 16:15:34 +0200 |
commit | df2773193ec1aaf7b53d3e51c6431cdb2ee313b9 (patch) | |
tree | faa89a6d508d217f40ab007d5ac0e4f3be9cda5c /src/core/malloc.c | |
parent | [menu] Add "--default" option to "choose" command (diff) | |
download | ipxe-df2773193ec1aaf7b53d3e51c6431cdb2ee313b9.tar.gz ipxe-df2773193ec1aaf7b53d3e51c6431cdb2ee313b9.tar.xz ipxe-df2773193ec1aaf7b53d3e51c6431cdb2ee313b9.zip |
[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 <mcb30@ipxe.org>
Diffstat (limited to 'src/core/malloc.c')
-rw-r--r-- | src/core/malloc.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/core/malloc.c b/src/core/malloc.c index d694f555..32fd5fc0 100644 --- a/src/core/malloc.c +++ b/src/core/malloc.c @@ -145,6 +145,18 @@ static unsigned int discard_cache ( void ) { } /** + * Discard all cached data + * + */ +static void discard_all_cache ( void ) { + unsigned int discarded; + + do { + discarded = discard_cache(); + } while ( discarded ); +} + +/** * Allocate a memory block * * @v size Requested size @@ -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 <stdio.h> /** |