Hi,
Popular memory leak detection tool like valgrind ,etc is simply crashing in our customized linux environment (montavista hardhat ,etc) , is there any other good memory leak detection tool which can be used on the target but which does not consume so much RAM like valgrind ?

Dani AI

Generated

Quick practical advice based on the thread so far: if Valgrind crashes on your MontaVista target you have two reliable paths — lightweight, on-target telemetry that runs with your constrained RAM, or heavier instrumentation run off-target (emulator or host) where memory is plentiful. ’s pointer to allocator-based tools and ’s note about vendor instrumented libraries are relevant — vendor profilers can be easiest if you can re-link, but don’t assume they’re the only route.

For development builds, compiler sanitizers (LeakSanitizer / AddressSanitizer) catch real leaks and give stack traces at allocation sites; they’re best used during local testing because their runtimes are intended for debugging rather than production. Build the test binary with the sanitizer (for example, link with LeakSanitizer via -fsanitize=leak) and run the instrumented binary on a machine with enough RAM. (clang.llvm.org)

For lower-overhead on-target profiling try a heap-profiling allocator you can enable at runtime (no massive instrumentation): link or preload a profiler-backed malloc and emit periodic heap snapshots. Example using gperftools’ heap profiler (link with -ltcmalloc or LD_PRELOAD) — set HEAPPROFILE and run to create .heap dumps you can analyze with pprof:

HEAPPROFILE=/tmp/myapp.hprof ./my_app

Linking a replacement allocator or preloading changes allocation behavior, so treat results as guidance, not absolute. (gperftools.github.io)

When you cannot re-link, use tiny in-process snapshots and /proc monitoring: call malloc_info(0, FILE*) or malloc_stats() at strategic points to capture allocator state, and sample /proc/<pid>/smaps or /proc/<pid>/status over time to spot steadily growing RSS or VM regions. Here is the simplest snapshot call pattern:

#include <malloc.h>
malloc_info(0, stdout); /* prints XML heap state */

These are low-cost and portable. (man7.org)

If the target is too small for heavy tools, reproduce the target userland on the host using QEMU (user- or system-mode) or a cross-built debug rootfs and run Valgrind / sanitizers there — you keep behavior close to target while using host resources for analysis. (qemu.eu)

Cautions: instrumentation changes timing/heap layout (false negatives/positives), and some tools require matching libc/debug symbols. Use a mix of the above: quick on-target snapshots for regression detection, and full sanitizer/heap-profiler runs in an emulator for root-cause fixes.

Recommended Answers

All 2 Replies

Take a look at these two articles which both provide details about the available programs/libraries for detecting memory leaks in *nix:
http://www.linuxjournal.com/article/6059
http://www.linuxjournal.com/article/6556

Other than Valgrind, it lists several tools/libraries.....

For programs compiled in C:
mtrace
memwatch
dmalloc

For C++ programs:
dmalloc
ccmalloc
NJAMD
YAMD
mpatrol
Insure++

Valgrind seems to work fine for me (EDIT: But then I'm not using it for embedded stuff!). As a consequence, I've not really used any of the others, so I can't make any solid recommendations.

I guess your best course of action would be to read the articles and try a few of the listed programs/libraries out and see what works best for you!

Cheers for now,
Jas.

commented: Nice looking list - thanks +20

I hv been using MPatrol for quite a long time for both memory profiling as well as my development activity.
It's the best one for embedded linux till date. It is having far more options and interesting results than Valgrind or any other in the open source.
Only thing is that, here u need to compile the application using MPatrol libraries for profiling it. I hv also ported the libraries to many of my target environments for embedded processor boards.

Check it out...
Cheers :icon_smile:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.