From: Tobias Diedrich Date: Mon, 19 Oct 2015 17:32:12 +0000 (+0200) Subject: Log a message when sbrk fails and return the correct error code. X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=7aa4eb70f3e8f0eaf5cf936e75ed2daf2b0b9b7f;p=oweals%2Fu-boot_mod.git 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). --- 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);