Please recommend some tools for c++ static analysis and memory leak detecting

B

Brian Jiang

Hi every guru, could you please recommend some tools for C++ static
analysis and memory leak detecting.
It will be better if they are free of charge :)
 
Ö

Öö Tiib

Hi every guru, could you please recommend some tools for C++ static
analysis and memory leak detecting.
It will be better if they are free of charge :)

Most simple is perhaps to compile your code with different compilers
to get various diagnostics. Also there are several open source tools
like cppcheck, oink and flawfinder, but these are usually platform
specific and often produce false alerts.

MS prefast is perhaps best that is "free", but it is closed source,
windows specific and integrated into MS compiler. It is "free" since
for example their free driver development kit has such compiler in it
and you can get it to compile your (likely non-driver) code. Buying a
Visual Studio that features compiler with static analysis is not cheap
(nor "professional").

Then there is option to get AST out from compilers like g++ or CLang
and make analyzing queries yourself based on that. It is not little
work.

If you have budget for statical analysis then you can of course buy a
tool. Most commercial static code analysis tools for C++ are pretty
expensive with prices ranging $1 000 to $10 000 per license.
 
V

Victor Bazarov

Hi every guru, could you please recommend some tools for C++ static
analysis and memory leak detecting.
It will be better if they are free of charge :)

Memory leak detectors are usually OS-specific, consider asking in the
newsgroup dedicated to your OS. There are also libraries that you can
build into your program that take over memory management, and they can
tell you whether/where you're have leaks. Sometimes that functionality
comes with the compiler itself, check your compiler manual.

Static analysis?... Code reviews by your team members are the best
thing. They aren't free, though, and usually only work with new code.
Which is to say, leave the old code alone. If you have indications that
it doesn't work, fix only what doesn't work. If you have no signs of
its malfunction, to statically analyze it is a waste of time.

V
 
V

Virchanza

Hi every guru, could you please recommend some tools for C++ static
analysis and memory leak detecting.
It will be better if they are free of charge :)

To keep track of memory leaks, you could open up "stdlib.h" and
change it to use your own malloc & free functions that keep track of
memory allocations and deallocations. You could use the "atexit"
function to print a summary when the program ends.
 
A

AnonMail2005

Hi every guru, could you please recommend some tools for C++ static
analysis and memory leak detecting.
It will be better if they are free of charge :)

google valgrind for a memory leak checker. It's for certain linux
platforms.

HTH
 
K

Katie

Hi every guru, could you please recommend some tools for C++ static
analysis and memory leak detecting.
It will be better if they are free of charge :)

Most memory leak detection software works at runtime rather than via
analysis. Valgrind and Purify are two good runtime tools.

Katie
 
D

DeMarcus

Hi every guru, could you please recommend some tools for C++ static
analysis and memory leak detecting.
It will be better if they are free of charge :)

Many has already pointed out Valgrind. Valgrind integrates well into the
Eclipse IDE and points out all occurrences of memory leaks directly in
the source code just like the compiler shows the errors. Pretty neat if
you like Eclipse.
 
R

Ramon F Herrera

Hi every guru, could you please recommend some tools for C++ static
analysis and memory leak detecting.
It will be better if they are free of charge :)

This reminds me of a potential nightmare I faced recently, but gcc
came to my rescue.

The code in question is based on OpenCV and is supposed to run on
Windows and Linux:

IplImage *gray8 = crop(im, &cvRect(left,top,right-left+1,bottom-top
+1));

The Visual Studio compilers (all of 3):

(a) Did not warn me of the problem.
(b) Emitted code that crashed _inconsistently_ in some computers, not
in others.

Good ole' gcc provided a friendly warning and the dangerous code was
rewritten thusly:

CvRect region = cvRect(left,top,right-left+1,bottom-top+1);
IplImage *gray8 = crop(im, &region);

Profuse thanks to the bearded hackers in my old stomping grounds by
MIT.

-Ramon
 
J

Jorgen Grahn

google valgrind for a memory leak checker. It's for certain linux
platforms.

And MacOS, and various *BSDs. It's not a static analysis tool though.
It will only analyze code that gets executed.

I know of no good free tools. I have used Coverity Prevent, but it's
expensive and I'm still not sure how good it really is. I've heard a
sales talk for Polyspace, but that one was very expensive.

http://en.wikipedia.org/wiki/List_of_tools_for_static_code_analysis

For memory leaks specifically: personally I find good (even decent!)
design takes care of them. Use the standard containers, avoid operator
new, make ownership clear and explicit, etc ... This works for new code,
and usually for legacy code too.

/Jorgen
 
J

Jorgen Grahn

Many has already pointed out Valgrind. Valgrind integrates well into the
Eclipse IDE and points out all occurrences of memory leaks directly in
the source code just like the compiler shows the errors. Pretty neat if
you like Eclipse.

IMHO, if you have *that* many memory leaks for such a long time,
finding the point of allocation in the source code is the least of
your problems ...

/Jorgen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,743
Latest member
WoodrowMea

Latest Threads

Top