]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
malloc: Support testing with realloc()
authorSimon Glass <sjg@chromium.org>
Tue, 30 Jul 2024 14:39:35 +0000 (08:39 -0600)
committerTom Rini <trini@konsulko.com>
Wed, 7 Aug 2024 14:49:10 +0000 (08:49 -0600)
At present in tests it is possible to cause an out-of-memory condition
with malloc() but not realloc(). Add support to realloc() too, so code
which uses that function can be tested.

Signed-off-by: Simon Glass <sjg@chromium.org>
common/dlmalloc.c

index 62e8557daa70ebeadc724feeee63558570c1cb9d..1e1602a24decb3ba28154def2de05ab25f8a23b6 100644 (file)
@@ -1698,6 +1698,10 @@ Void_t* rEALLOc_impl(oldmem, bytes) Void_t* oldmem; size_t bytes;
                panic("pre-reloc realloc() is not supported");
        }
 #endif
+  if (CONFIG_IS_ENABLED(UNIT_TEST) && malloc_testing) {
+    if (--malloc_max_allocs < 0)
+      return NULL;
+  }
 
   newp    = oldp    = mem2chunk(oldmem);
   newsize = oldsize = chunksize(oldp);