From 8db68825038402b92117afe3aaedb1359cbc281b Mon Sep 17 00:00:00 2001 From: Omar Chebib Date: Mon, 4 Aug 2025 16:33:21 +0800 Subject: [PATCH] fix(heap): fix a bug where the biggest heap would be NULL on boot Closes https://github.com/espressif/esp-idf/issues/17232 --- components/heap/heap_task_info.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/components/heap/heap_task_info.c b/components/heap/heap_task_info.c index 880bf358fd..8844e4fea8 100644 --- a/components/heap/heap_task_info.c +++ b/components/heap/heap_task_info.c @@ -57,12 +57,16 @@ FORCE_INLINE_ATTR heap_t* find_biggest_heap(void) heap_t *heap = NULL; heap_t *biggest_heap = NULL; SLIST_FOREACH(heap, ®istered_heaps, next) { - if (biggest_heap == NULL) { + /* In the case where we are currently looking for the biggest heap during startup, + * before the scheduler stated, all the memory regions marked as startup stacks will + * be NULL here. As such, they must be ignored. After boot up, this statement will + * never be true. */ + if (heap->heap == NULL) { + /* Continue the loop */ + } else if (biggest_heap == NULL) { biggest_heap = heap; } else if ((biggest_heap->end - biggest_heap->start) < (heap->end - heap->start)) { biggest_heap = heap; - } else { - // nothing to do here } } return biggest_heap;