Skip to content
Snippets Groups Projects
Commit 27405448 authored by Wolfgang Denk's avatar Wolfgang Denk
Browse files

malloc: return NULL if not initialized yet


When malloc() was called before it was properly initialized
(as would happen if when used before relocation to RAM) it returned
random, non-NULL values, which called all kinds of difficult to debug
subsequent errors.

Make sure to return NULL when initialization was not done yet.

Signed-off-by: default avatarWolfgang Denk <wd@denx.de>
parent f0983371
No related branches found
No related tags found
No related merge requests found
......@@ -2179,6 +2179,12 @@ Void_t* mALLOc(bytes) size_t bytes;
INTERNAL_SIZE_T nb;
/* check if mem_malloc_init() was run */
if ((mem_malloc_start == 0) && (mem_malloc_end == 0)) {
/* not initialized yet */
return 0;
}
if ((long)bytes < 0) return 0;
nb = request2size(bytes); /* padded request size; */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment