Skip to content

Commit

Permalink
[malloc] Discard all cached data on shutdown
Browse files Browse the repository at this point in the history
Allow detection of genuine memory leaks by ensuring that all cached
data is freed on shutdown.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
  • Loading branch information
mcb30 committed May 4, 2012
1 parent 838a76a commit df27731
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/core/malloc.c
Expand Up @@ -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
*
Expand Down Expand Up @@ -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>
/**
Expand Down

0 comments on commit df27731

Please sign in to comment.