Browse Source

[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>
tags/v1.20.1
Michael Brown 13 years ago
parent
commit
df2773193e
1 changed files with 25 additions and 0 deletions
  1. 25
    0
      src/core/malloc.c

+ 25
- 0
src/core/malloc.c View File

144
 	return discarded;
144
 	return discarded;
145
 }
145
 }
146
 
146
 
147
+/**
148
+ * Discard all cached data
149
+ *
150
+ */
151
+static void discard_all_cache ( void ) {
152
+	unsigned int discarded;
153
+
154
+	do {
155
+		discarded = discard_cache();
156
+	} while ( discarded );
157
+}
158
+
147
 /**
159
 /**
148
  * Allocate a memory block
160
  * Allocate a memory block
149
  *
161
  *
458
 	.initialise = init_heap,
470
 	.initialise = init_heap,
459
 };
471
 };
460
 
472
 
473
+/**
474
+ * Discard all cached data on shutdown
475
+ *
476
+ */
477
+static void shutdown_cache ( int booting __unused ) {
478
+	discard_all_cache();
479
+}
480
+
481
+/** Memory allocator shutdown function */
482
+struct startup_fn heap_startup_fn __startup_fn ( STARTUP_EARLY ) = {
483
+	.shutdown = shutdown_cache,
484
+};
485
+
461
 #if 0
486
 #if 0
462
 #include <stdio.h>
487
 #include <stdio.h>
463
 /**
488
 /**

Loading…
Cancel
Save