]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[malloc] Discard all cached data on shutdown
authorMichael Brown <mcb30@ipxe.org>
Mon, 30 Apr 2012 19:33:23 +0000 (20:33 +0100)
committerMichael Brown <mcb30@ipxe.org>
Fri, 4 May 2012 14:15:34 +0000 (15:15 +0100)
Allow detection of genuine memory leaks by ensuring that all cached
data is freed on shutdown.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/core/malloc.c

index d694f5559aabcc458e9c1367a3e3917a3256970f..32fd5fc0e9093afab4eddd30e512d07a6ebb9fe0 100644 (file)
@@ -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 <stdio.h>
 /**