cancel
Showing results for 
Search instead for 
Did you mean: 

Memory leak detection or profilers

MSing.8
Associate III

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.

5 REPLIES 5
TDK
Guru

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.

If you feel a post has answered your question, please click "Accept as Solution".
MSing.8
Associate III

Is there a way in STM32CubeIDE to see heap and which pointers(variables) are writing or allocating memory on heap?

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.

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
MSing.8
Associate III

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:

https://nadler.com/embedded/newlibAndFreeRTOS.html