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:08

Also worth using if you're on Linux using glibc is the built-in debug heap code. To use it, link with -lmcheck or define (and export) the MALLOC_CHECK_ environment variable with the value 1, 2, or 3. The glibc manual provides more information.

This mode is most useful for detecting double-frees, and it often finds writes outside the allocated memory area when doing a free. I don't think it reports leaked memory.

查看更多
等我变得足够好
3楼-- · 2019-01-16 07:12

If you have the money: IBM Rational Purify is an extremely powerful industry-strength memory leak and memory corruption detector for C/C++. Exists for Windows, Solaris and Linux. If you're linux-only and want a cheap solution, go for Valgrind.

查看更多
欢心
4楼-- · 2019-01-16 07:13

I had quite some hits with cppcheck, which does static analysis only. It is open source and has a command line interface (I did not use it in any other way).

查看更多
爱情/是我丢掉的垃圾
5楼-- · 2019-01-16 07:16

I've had minimal love for any memory leak detectors. Typically there are far too many false positives for them to be of any use. I would recommend these two as beiong the least intrusive:

GlowCode

Debug heap

查看更多
女痞
6楼-- · 2019-01-16 07:16

At university when I was doing most things under Unix Solaris I used gdb.

However I would go with valgrind under Linux.

查看更多
够拽才男人
7楼-- · 2019-01-16 07:17

Mudflap for gcc! It actually compiles the checks into the executable. Just add

-fmudflap -lmudflap

to your gcc flags.

查看更多
登录 后发表回答