ソースを参照

[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>
tags/v1.20.1
Michael Brown 6年前
コミット
42eedb04c1
1個のファイルの変更8行の追加1行の削除
  1. 8
    1
      src/core/malloc.c

+ 8
- 1
src/core/malloc.c ファイルの表示

284
 	size_t post_size;
284
 	size_t post_size;
285
 	struct memory_block *pre;
285
 	struct memory_block *pre;
286
 	struct memory_block *post;
286
 	struct memory_block *post;
287
+	unsigned int discarded;
287
 	void *ptr;
288
 	void *ptr;
288
 
289
 
289
 	/* Sanity checks */
290
 	/* Sanity checks */
371
 		}
372
 		}
372
 
373
 
373
 		/* Try discarding some cached data to free up memory */
374
 		/* Try discarding some cached data to free up memory */
374
-		if ( ! discard_cache() ) {
375
+		DBGC ( &heap, "Attempting discard for %#zx (aligned %#zx+%zx), "
376
+		       "used %zdkB\n", size, align, offset, ( usedmem >> 10 ) );
377
+		valgrind_make_blocks_noaccess();
378
+		discarded = discard_cache();
379
+		valgrind_make_blocks_defined();
380
+		check_blocks();
381
+		if ( ! discarded ) {
375
 			/* Nothing available to discard */
382
 			/* Nothing available to discard */
376
 			DBGC ( &heap, "Failed to allocate %#zx (aligned "
383
 			DBGC ( &heap, "Failed to allocate %#zx (aligned "
377
 			       "%#zx)\n", size, align );
384
 			       "%#zx)\n", size, align );

読み込み中…
キャンセル
保存