I am using mbed OS on the STM32 platform.
Compiler: ARM GCC toolchain -9-2019-q4-major)
Sample code fragment:
print_heap_and_isr_stack_info();
void *ptr = malloc(1000);
print_heap_and_isr_stack_info();
if (ptr == NULL)
{
tr_info("malloc failed");
}
free(ptr);
print_heap_and_isr_stack_info();
Statistics output:-
heap ( start: 00000000 end: 00000000 size: 00000000 used: 00000A5C ) alloc ( ok: 00000006 fail: 00000000 )
)
heap ( start: 00000000 end: 00000000 size: 00000000 used: 00000E44 ) alloc ( ok: 00000007 fail: 00000000 )
)
heap ( start: 00000000 end: 00000000 size: 00000000 used: 00000E44 ) alloc ( ok: 00000006 fail: 00000000 )
Before allocation - used : 00000A5C
After allocation - used: 00000E44 (correct as 1000 bytes allocated)
After calling free() - used: 00000E44 (concern).
Similar behaviour is observed in main project where dynamic allocation is used and heap statics showing full consumption of heap memory:
heap ( start: 20007B80 end: 20018000 size: 00010480 used: 0000FB74 ) alloc ( ok: 000000F7 fail: 00000000 )
And mbed os throws error:
++ MbedOS Error Info ++
Error Status: 0x8001011F Code: 287 Module: 1
Error Message: Operator new out of memory