Memory leak detectors for C?

2019-01-16 06:53发布

What memory leak detectors have people had a good experience with?

Here is a summary of the answers so far:

Valgrind - Instrumentation framework for building dynamic analysis tools.

Electric Fence - A tool that works with GDB

Splint - Annotation-Assisted Lightweight Static Checking

Glow Code - This is a complete real-time performance and memory profiler for Windows and .NET programmers who develop applications with C++, C#, or any .NET Framework

Also see this stackoverflow post.

17条回答
在下西门庆
2楼-- · 2019-01-16 07:27

second the valgrind... and I'll add electric fence.

查看更多
Fickle 薄情
3楼-- · 2019-01-16 07:29

On Windows, I have used Visual Leak Detector. Integrates with VC++, easy to use (just include a header and set LIB to find the lib), open source, free to use FTW.

查看更多
The star\"
4楼-- · 2019-01-16 07:31

No one mentioned clang's MSan, which is quite powerful. It is officially supported on Linux only, though.

查看更多
5楼-- · 2019-01-16 07:32

For Win32 debugging of memory leaks I have had very good experiences with the plain old CRT Debug Heap, that comes as a lib with Visual C.

In a Debug build malloc (et al) get redefined as _malloc_dbg (et al) and there are other calls to retrieve results, which are all undefined if _DEBUG is not set. It sets up all sorts of boundary guards on the heap, and allows you to diplay the results at any time.

I had a few false positives when I was witting some time routines that messed with the library run time allocations until I discovered _CRT_BLOCK.

I had to produce first DOS, then Win32 console and services that would run for ever. As far as I know there are no memory leaks, and in at least one place the code run for two years unattended before the monitor on the PC failed (though the PC was fine!).

查看更多
何必那么认真
6楼-- · 2019-01-16 07:32

The granddaddy of these tools is the commercial, closed-source Purify tool, which was sold to IBM and then to UNICOM

Parasoft's Insure++ (source code instrumentation) and valgrind (open source) are the two other real competitors.

Trivia: the original author of Purify, Reed Hastings, went on to found NetFlix.

查看更多
登录 后发表回答