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).
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);