summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorMichael Brown2017-09-04 15:00:32 +0200
committerMichael Brown2017-09-04 15:09:17 +0200
commit42eedb04c1ad71548043c33ef1996dfe8e524996 (patch)
treefa116cf39c744219ce2690deb830fcb1721ec5c3 /src/core
parent[romprefix] Avoid unaligned accesses within ROM headers (diff)
downloadipxe-42eedb04c1ad71548043c33ef1996dfe8e524996.tar.gz
ipxe-42eedb04c1ad71548043c33ef1996dfe8e524996.tar.xz
ipxe-42eedb04c1ad71548043c33ef1996dfe8e524996.zip
[malloc] Avoid false positive warnings from valgrind
Calling discard_cache() is likely to result in a call to free_memblock(), which will call valgrind_make_blocks_noaccess() before returning. This causes valgrind to report an invalid read on the next iteration through the loop in alloc_memblock(). Fix by explicitly calling valgrind_make_blocks_defined() after discard_cache() returns. Also call valgrind_make_blocks_noaccess() before calling discard_cache(), to guard against free list corruption while executing cache discarders. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/core')
-rw-r--r--src/core/malloc.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/core/malloc.c b/src/core/malloc.c
index 6ddc08b7..91c8e4d3 100644
--- a/src/core/malloc.c
+++ b/src/core/malloc.c
@@ -284,6 +284,7 @@ void * alloc_memblock ( size_t size, size_t align, size_t offset ) {
size_t post_size;
struct memory_block *pre;
struct memory_block *post;
+ unsigned int discarded;
void *ptr;
/* Sanity checks */
@@ -371,7 +372,13 @@ void * alloc_memblock ( size_t size, size_t align, size_t offset ) {
}
/* Try discarding some cached data to free up memory */
- if ( ! discard_cache() ) {
+ DBGC ( &heap, "Attempting discard for %#zx (aligned %#zx+%zx), "
+ "used %zdkB\n", size, align, offset, ( usedmem >> 10 ) );
+ valgrind_make_blocks_noaccess();
+ discarded = discard_cache();
+ valgrind_make_blocks_defined();
+ check_blocks();
+ if ( ! discarded ) {
/* Nothing available to discard */
DBGC ( &heap, "Failed to allocate %#zx (aligned "
"%#zx)\n", size, align );