cancel
Showing results for 
Search instead for 
Did you mean: 

Are there any tools available for debugging memory leaks?

Starman
Associate II

I'm using an STM32F767ZI, and am programming it in C without any additional libraries (bare metal).

I believe there is a memory leak somewhere as a memory allocation that typically would work seems to fail after the program has been running for some time.

I'm familiar with tools such as dmalloc and valgrind, however an embedded environment is (obviously) very different and adds complications.

Are there any reliable tools, similar to the two named above, which could help me to track down memory leaks? Since the system is intended to run indefinitely, it would be preferable if the tool offered functions which can be called from within GDB in order to analyse the currently allocated memory.

If not, what is the best way to go about making something like this myself which can give useful info about where exactly the memory was allocated?

From searching around, I've come across a variety of (unhelpful for my use-case) answers, including suggesting that dynamically allocated memory should be entirely avoided? My system makes HTTP requests, parses them as well as the JSON body, then extracts a value at a specific key. It would be nice to avoid dynamically allocated memory if possible, so is there any way to go about it for something like this? Clearly the issue is that the HTTP response size is unknown, as well as the JSON body.

For reference, here is the link to the HTTP parser I've written: https://github.com/Starman3787/http

And this is a link to the code on the embedded system, if it helps (the HTTP parser used here is essentially the same, although slightly modified to work on an embedded system and reading the response over UART): https://github.com/Starman3787/btc-split-flap/tree/dev/software_v2

10 REPLIES 10

Understood, will give this a go.

Thanks so much for your help. 🙂