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

Discussion in 'C++' started by Brian Jiang, Dec 21, 2010.

  1. Brian Jiang

    Brian Jiang Guest

    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 :)
     
    Brian Jiang, Dec 21, 2010
    #1
    1. Advertising

  2. Brian Jiang

    Öö Tiib Guest

    Re: Please recommend some tools for c++ static analysis and memoryleak detecting

    On Dec 21, 3:04 pm, Brian Jiang <> wrote:
    > 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.
     
    Öö Tiib, Dec 21, 2010
    #2
    1. Advertising

  3. Re: Please recommend some tools for c++ static analysis and memoryleak detecting

    On 12/21/2010 8:04 AM, Brian Jiang wrote:
    > 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
    --
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Dec 21, 2010
    #3
  4. Brian Jiang

    Virchanza Guest

    Re: Please recommend some tools for c++ static analysis and memoryleak detecting

    On Dec 21, 1:04 pm, Brian Jiang <> wrote:
    > 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.
     
    Virchanza, Dec 21, 2010
    #4
  5. Brian Jiang

    Guest

    Re: Please recommend some tools for c++ static analysis and memoryleak detecting

    On Dec 21, 8:04 am, Brian Jiang <> wrote:
    > 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
     
    , Dec 21, 2010
    #5
  6. Brian Jiang

    Brian Jiang Guest

    Re: Please recommend some tools for c++ static analysis and memoryleak detecting

    Thanks a lot everybody.
     
    Brian Jiang, Dec 23, 2010
    #6
  7. Brian Jiang

    Brian Jiang Guest

    Re: Please recommend some tools for c++ static analysis and memoryleak detecting

    Thanks a lot everybody.
     
    Brian Jiang, Dec 23, 2010
    #7
  8. Brian Jiang

    Katie Guest

    Re: Please recommend some tools for c++ static analysis and memoryleak detecting

    On Dec 21, 1:04 pm, Brian Jiang <> wrote:
    > 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
    --
    CoderStack
    http://www.coderstack.co.uk/c -jobs
    The Software Developer Job Board
     
    Katie, Dec 25, 2010
    #8
  9. Brian Jiang

    DeMarcus Guest

    Re: Please recommend some tools for c++ static analysis and memoryleak detecting

    On 2010-12-21 14:04, Brian Jiang wrote:
    > 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.
     
    DeMarcus, Dec 26, 2010
    #9
  10. Re: Please recommend some tools for c++ static analysis and memoryleak detecting

    On Dec 21, 7:04 am, Brian Jiang <> wrote:
    > 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
     
    Ramon F Herrera, Dec 27, 2010
    #10
  11. Brian Jiang

    Jorgen Grahn Guest

    Re: Please recommend some tools for c++ static analysis and memoryleak detecting

    On Tue, 2010-12-21, wrote:
    > On Dec 21, 8:04 am, Brian Jiang <> wrote:
    >> 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.


    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

    --
    // Jorgen Grahn <grahn@ Oo o. . .
    \X/ snipabacken.se> O o .
     
    Jorgen Grahn, Dec 30, 2010
    #11
  12. Brian Jiang

    Jorgen Grahn Guest

    Re: Please recommend some tools for c++ static analysis and memoryleak detecting

    On Sun, 2010-12-26, DeMarcus wrote:
    > On 2010-12-21 14:04, Brian Jiang wrote:
    >> 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.


    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

    --
    // Jorgen Grahn <grahn@ Oo o. . .
    \X/ snipabacken.se> O o .
     
    Jorgen Grahn, Dec 30, 2010
    #12
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Derek
    Replies:
    2
    Views:
    437
    Ron Natalie
    Mar 4, 2005
  2. Don

    Static Code Analysis Tools

    Don, Jul 25, 2003, in forum: C Programming
    Replies:
    1
    Views:
    400
    Eric Sosman
    Jul 25, 2003
  3. Richard
    Replies:
    10
    Views:
    704
    Francesco
    Sep 6, 2009
  4. ssubbarayan
    Replies:
    5
    Views:
    2,422
    Dave Hansen
    Nov 3, 2009
  5. Elisa
    Replies:
    20
    Views:
    1,065
    sadsailor
    Oct 30, 2011
Loading...

Share This Page