Skip to content

Commit 2fd71e8

Browse files
committed
protect heap_caps_get_allocated_size(), don't exit on nullptr
1 parent a65cb40 commit 2fd71e8

1 file changed

Lines changed: 1 addition & 2 deletions

File tree

wled00/util.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -904,9 +904,8 @@ void *d_realloc_malloc_nofree(void *ptr, size_t size) {
904904
DEBUG_PRINTF("* d_realloc_malloc_nofree() realloc to %u bytes requested.\n", size);
905905
void* buffer = nullptr;
906906
#if (ESP_IDF_VERSION_MAJOR > 3)
907-
if (!ptr) return ptr; // heap_caps_get_allocated_size crashes on nullptr
908907
// only basic sanity checks possible: prefer PSRAM if DRAM is low
909-
size_t oldSize = heap_caps_get_allocated_size(ptr);
908+
size_t oldSize = ptr ? heap_caps_get_allocated_size(ptr) : 0; // heap_caps_get_allocated_size crashes on nullptr
910909
size_t delta = (size > oldSize) ? (size - oldSize) : 0;
911910
if ((delta == 0) || isOkForDRAMHeap(delta)) { // prefer DRAM
912911
buffer = heap_caps_realloc_prefer(ptr, size, 3, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT, MALLOC_CAP_DEFAULT);

0 commit comments

Comments
 (0)