From: Wolfgang Denk Date: Fri, 15 Jan 2010 10:20:10 +0000 (+0100) Subject: malloc: return NULL if not initialized yet X-Git-Tag: v2010.03-rc1~155 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2740544881f652566756815dda4da0bcd946e9de;p=platform%2Fkernel%2Fu-boot.git 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: Wolfgang Denk --- diff --git a/common/dlmalloc.c b/common/dlmalloc.c index 735b344..205fc40 100644 --- a/common/dlmalloc.c +++ b/common/dlmalloc.c @@ -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; */