Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

memory leak in an embedded system

I need to check for a memory leak in an embedded system.

The IDE is HEW and we are using uCOSIII RTOS.

Valgrind does not support the above configurations. Can you please suggest a tool or a method to check for memory leaks?

like image 759
user2086002 Avatar asked Sep 05 '25 03:09

user2086002


2 Answers

First rule of dynamically allocating memory in embedded systems is "don't". Allocate it all once at the start of execution and then leave well alone. Otherwise you have to assess and decide what to do when a malloc (or similar operation) fails.

If you must dynamically allocate memory at runtime, then at its simplest you may be able to use a logging infrastructure to track calls to malloc/free by writing wrappers around them. Then you can track where and when the allocations and deallocations are happening and hopefully see what is missing.

like image 64
Martin Thompson Avatar answered Sep 09 '25 17:09

Martin Thompson


Take a look at libtalloc, the core memory allocator used in Samba. It may not work out-of-the-box for you if you don't have atexit() or stdio.h, but it shouldn't take too much work to port it to your environment.

Have a look at talloc_enable_leak_report_full() and talloc_report_full() (among others) to get you started.

like image 25
Ben Avatar answered Sep 09 '25 16:09

Ben