heap_caps_alloc_failed_hook called for 0 byte allocation in bluetooth app
Posted: Wed Jul 14, 2021 8:27 am
So we have an application which is using bluetooth and we are adding a characteristic. The code ends up in BTA_GATTS_AddCharacteristic at line 242 which looks like this in the current master branch:
Link: https://github.com/espressif/esp-idf/bl ... api.c#L242
So len = 0 and it looks like we are going to get NULL returned and the library handles this by only copying data if we have a valid pointer.
The crux of the problem is that if we register a heap_caps_malloc_failed_hook then the hook is called and we are information that a 0 byte request is being made.
Is this expected behaviour? I was expecting the hook to be called if we did not have enough memory free to allow the application to take action but the 0 bytes allocation request came as a shock to both me and the application
Thanks in advance,
Mark
Code: Select all
p_buf->attr_val.attr_val = (uint8_t *)osi_malloc(len);
if(p_buf->attr_val.attr_val != NULL){
memcpy(p_buf->attr_val.attr_val, attr_val->attr_val, attr_val->attr_len);
}
So len = 0 and it looks like we are going to get NULL returned and the library handles this by only copying data if we have a valid pointer.
The crux of the problem is that if we register a heap_caps_malloc_failed_hook then the hook is called and we are information that a 0 byte request is being made.
Is this expected behaviour? I was expecting the hook to be called if we did not have enough memory free to allow the application to take action but the 0 bytes allocation request came as a shock to both me and the application
Thanks in advance,
Mark