From 7aa4eb70f3e8f0eaf5cf936e75ed2daf2b0b9b7f Mon Sep 17 00:00:00 2001 From: Tobias Diedrich Date: Mon, 19 Oct 2015 19:32:12 +0200 Subject: [PATCH] Log a message when sbrk fails and return the correct error code. Returning NULL leads to subtle corruption and malloc returning memory addresses in the user mode space range (0x00000000-0x7fffffff). This in turn also breaks everything that implicitly relies on malloc()ed memory to be zeroed at the beginning (since the malloc arena is initially zeroed). --- u-boot/lib_mips/board.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/u-boot/lib_mips/board.c b/u-boot/lib_mips/board.c index 1572043..c340b0a 100644 --- a/u-boot/lib_mips/board.c +++ b/u-boot/lib_mips/board.c @@ -84,7 +84,9 @@ void *sbrk(ptrdiff_t increment){ ulong new = old + increment; if((new < mem_malloc_start) || (new > mem_malloc_end)){ - return(NULL); + printf("sbrk: Out of memory (%d requested > %d available)\n", + increment, mem_malloc_end - old); + return((void*)MORECORE_FAILURE); } mem_malloc_brk = new; return((void *)old); -- 2.25.1