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

Valgrind under linux is fairly good; I have no experience under Windows with this.

查看更多
在下西门庆
3楼-- · 2019-01-16 07:21

lint (very similar open-source tool called splint)

查看更多
老娘就宠你
4楼-- · 2019-01-16 07:21

This question maybe old, but I'll answer it anyway - maybe my answer will help someone to find their memory leaks.

This is my own project - I've put it as open source code:

https://sourceforge.net/projects/diagnostic/

Windows 32 & 64-bit platforms are supported, native and mixed mode callstacks are supported.

.NET garbage collection is not supported. (C++ cli's gcnew or C#'s new)

It high performance tool, and does not require any integration (unless you really want to integrate it).

Complete manual can be found here:

http://diagnostic.sourceforge.net/index.html

Don't be afraid of how much it actually detects leaks it your process. It catches memory leaks from whole process. Analyze only biggest leaks, not all.

查看更多
Fickle 薄情
5楼-- · 2019-01-16 07:23

I'll second the valgrind as an external tool for memory leaks.
But, for most of the problems I've had to solve I've always used internally built tools. Sometimes the external tools have too much overhead or are too complicated to set up.

Why use already written code when you can write your own :)

I joke, but sometimes you need something simple and it's faster to write it yourself. Usually I just replace calls to malloc() and free() with functions that keep better track of who allocates what. Most of my problems seem to be someone forgot to free and this helps to solve that problem.

It really depends on where the leak is, and if you knew that, then you would not need any tools. But if you have some insight into where you think it's leaking, then put in your own instrumentation and see if it helps you.

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

Our CheckPointer tool can do this for GNU C 3/4 and, MS dialects of C, and GreenHills C. It can find memory management problems that Valgrind cannot.

If your code simply leaks, on exit CheckPointer will tell you where all the unfreed memory was allocated.

查看更多
Root(大扎)
7楼-- · 2019-01-16 07:26

Painful but if you had to use one..
I'd recommend the DevPartner BoundsChecker suite.. that's what people at my workplace use for this purpose. Paid n proprietary.. not freeware.

查看更多
登录 后发表回答