heap_caps_malloc was called but failed to allocate
Posted: Wed May 24, 2023 7:24 am
Hello. I have some issues with heap memory allocation. I have started to dig into how it works.
in my code, I have registered failed alloc callback:
Occasionally, I can see the following errors pop up in the logs:
I started looking into malloc function declaration and noticed something strange:
In flash_mock.cpp I have found the following:
Is this function deprecated? what is flash_mock.cpp?
In the heap_caps.c I have also found the real heap_caps_malloc function declaration:
in my code, I have registered failed alloc callback:
Code: Select all
esp_err_t error = heap_caps_register_failed_alloc_callback(heap_caps_alloc_failed_hook);
Code: Select all
void heap_caps_alloc_failed_hook(size_t requested_size, uint32_t caps, const char *function_name) {
printf("%s was called but failed to allocate %d bytes with %ld capabilities. \n", function_name, requested_size,caps);
}
Code: Select all
heap_caps_malloc was called but failed to allocate 1696 bytes with 6144 capabilities.
In flash_mock.cpp I have found the following:
Code: Select all
void *heap_caps_malloc( size_t size, uint32_t caps )
{
return NULL;
}
In the heap_caps.c I have also found the real heap_caps_malloc function declaration:
Code: Select all
IRAM_ATTR void *heap_caps_malloc( size_t size, uint32_t caps){
void* ptr = heap_caps_malloc_base(size, caps);
if (!ptr && size > 0){
heap_caps_alloc_failed(size, caps, __func__);
}
return ptr;
}