]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
malloc: return NULL if not initialized yet
authorWolfgang Denk <wd@denx.de>
Fri, 15 Jan 2010 10:20:10 +0000 (11:20 +0100)
committerWolfgang Denk <wd@denx.de>
Fri, 15 Jan 2010 12:26:20 +0000 (13:26 +0100)
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 <wd@denx.de>
common/dlmalloc.c

index 735b3443e63a556e0af9dbd63f3def0286f85a0a..205fc40ac83d866a7581ab28a9793093512bde40 100644 (file)
@@ -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; */