AP_MultiHeap: initialize only if heap allocation succeeded

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>
This commit is contained in:
Rhys Mainwaring 2025-01-04 19:38:59 +00:00 committed by Randy Mackay
parent df24d3a61d
commit f7d5f0f8f1

View File

@ -36,9 +36,9 @@ void *MultiHeap::heap_create(uint32_t size)
{ {
struct heap *new_heap = (struct heap*)malloc(sizeof(struct heap)); struct heap *new_heap = (struct heap*)malloc(sizeof(struct heap));
if (new_heap != nullptr) { if (new_heap != nullptr) {
new_heap->magic = HEAP_MAGIC;
new_heap->max_heap_size = size; new_heap->max_heap_size = size;
} }
new_heap->magic = HEAP_MAGIC;
return (void *)new_heap; return (void *)new_heap;
} }