summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorWolfgang Denk <wd@denx.de>2010-01-15 11:20:10 +0100
committerWolfgang Denk <wd@denx.de>2010-01-15 13:26:20 +0100
commit2740544881f652566756815dda4da0bcd946e9de (patch)
tree2a76867d094fa88bdfdd6c229fa30ad448dd3123 /common
parentf098337152ca48e135448f5e7836cce938e12bc0 (diff)
downloadblackbird-obmc-uboot-2740544881f652566756815dda4da0bcd946e9de.tar.gz
blackbird-obmc-uboot-2740544881f652566756815dda4da0bcd946e9de.zip
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 <wd@denx.de>
Diffstat (limited to 'common')
-rw-r--r--common/dlmalloc.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/common/dlmalloc.c b/common/dlmalloc.c
index 735b3443e6..205fc40ac8 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; */
OpenPOWER on IntegriCloud