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: Simon Glass <simon.glass@canonical.com>
(cherry picked from commit 2740544881)
This commit is contained in:
@@ -4582,6 +4582,11 @@ static void* tmalloc_small(mstate m, size_t nb) {
|
||||
#if !ONLY_MSPACES
|
||||
|
||||
void* dlmalloc(size_t bytes) {
|
||||
#ifdef __UBOOT__
|
||||
/* Return NULL if not initialized yet */
|
||||
if (!mem_malloc_start && !mem_malloc_end)
|
||||
return NULL;
|
||||
#endif
|
||||
/*
|
||||
Basic algorithm:
|
||||
If a small request (< 256 bytes minus per-chunk overhead):
|
||||
|
||||
Reference in New Issue
Block a user