Debugging memory leaks ...

14 Feb 2018

Since I was there and finally found the issue I would like to share the outcome.

What I found useful was:

  • enable malloc/free tracing
  • enable heap/stack stats

The first part is actually simple. Just add the macro "MBED_MEM_TRACING_ENABLED=1" to the app config. It will output the results of malloc, realloc and free and you can see whether there are strange allocations. The output is somewhat unreadable, so I also decided to write a little script which acts as a filter for the UART output and counts allocations/deallocations as well as how much heap space was allocated: mbed-memtrace-logger.

The script provides a nice way to check that at the same point in your code, you have the same allocated amount.

However, also useful was the project mbed-memory-status, which adds some functions to dump the currently used stack (all threads) as well as heap usage.

Both combined, with some debugging and digging found the issue.

Hope it helps others.

Leo.