diff mbox series

[v4,1/4] malloc: Support testing with realloc()

Message ID 20240726140038.194946-2-sjg@chromium.org
State Superseded
Delegated to: Tom Rini
Headers show
Series alist: Implement a pointer list / array of structs | expand

Commit Message

Simon Glass July 26, 2024, 2 p.m. UTC
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>
---

(no changes since v1)

 common/dlmalloc.c | 4 ++++
 1 file changed, 4 insertions(+)
diff mbox series

Patch

diff --git a/common/dlmalloc.c b/common/dlmalloc.c
index 62e8557daa7..1e1602a24de 100644
--- a/common/dlmalloc.c
+++ b/common/dlmalloc.c
@@ -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);