2022-04-02 12:11 PM
I am using STM32CubeIDE suite of tools on windows.
MCU is STM32F4. Debugger is ST-Link V2.
Is there a way to identify memory leak in the code i wrote for my MCU ? Preferably in STM32CubeIDE as its through this tool I upload & debug firmware for MCU.
I read about valgrind, it is non-trivial if at all feasible to integrate it into STM32CubeIDE. I think its for unix based system and not for windows which I could be wrong on too.
2022-04-02 12:33 PM
Detecting memory leaks in C applications is very nontrivial and usually invasive. Typically it involves redirecting malloc/free calls to an intermediate to track things. STM32CubeIDE doesn't have anything like this built in.
2022-04-02 01:13 PM
Is there a way in STM32CubeIDE to see heap and which pointers(variables) are writing or allocating memory on heap?
2022-04-02 02:38 PM
The standard C library of CubeIDE is newlib. It provides malloc, free and their friends.
You can look at its sources and figure out how to instrument it for leak detection.
Here is a useful post about the newlib details.
Even without library internals. the linker (ld) allows to "wrap" malloc, free and so on in your own wrapper functions.
2022-04-02 02:51 PM
Generally one can do simple wrapping of malloc/free to front-load some data to identifier owners, size, linked-list, etc. Also double check for multiple releases.And ability to walk current allocations to check for orphans, and resource leaks.
The regular heap can typically be walked via it's own linked-list, to check for usage and fragmentation. So you can see resources diminishing.
2022-04-02 06:34 PM
TDK, Pavel & Tesla,
Thank you for the direction.
I am going through this article and see how I can apply the learning to the code in which i want to find leaks: