Slashdot Mirror


Memory Leaks

G3ck0G33k writes: "Is there any free software version/clone of Rational's programs PureCoverage and/or Purify? I have worked with both of them on fairly large projects (>150,000 lines of code) and they were great to work with. When the first runs of Purify found nearly fifty instances of minor memory leaks, I was deeply frustrated/impressed. A free (perhaps GPLd) clone would be so interesting; Rational's licensing is killing my current budget. Of course, the more kinds of leaks it may detect, the better. GeckoGeek" We had a similar question last year but there's no harm in seeing what the current answers are.

3 of 34 comments (clear)

  1. Bounded pointers, etc. by Lumpish+Scholar · · Score: 5, Informative

    For the other kinds of stuff Purify does (aside from memory leaks), look at Greg McGary's bounded pointer work.

    Bad news: You'll have to build your own gcc (Greg's changes haven't yet been accepted in to the gcc trunk), and all your libraries (just as Purify re-writes all your libraries).

    Good news: The resulting code is much faster than Purify'ed code, and finds some problems Purify doesn't. I know of a major software development effort (hundreds of developers, millions of lines of code; sorry, can't give details) that uses bounded pointers to great advantage.

    Other tools: GNU Checker, dbmalloc, Bruce Perens' Electric Fence, MemProf, mpatrol, and Mprof; Google searches will turn them all up.

    --
    Stupid job ads, weird spam, occasional insight at
  2. Memory leak detection by pthisis · · Score: 5, Informative

    The Boehm-Weiser garbage-collecting malloc() can be built in a leak-detection mode. Every time an object is leaked, it prints out the address of the memory in question. Do that. Then it's 15 lines of python to correlate that back with the malloc() calls; I wrapped malloc/realloc to print out the line number and filename, e.g.

    void *our_malloc(size_t howbig, int line, char * file)
    {
    void *p;

    p=GC_malloc(howbig);
    fprintf(stderr, "Line %d of %s/%s(): %p\n", line, file, p);
    return p;
    }
    #define malloc(x) our_malloc(x, __LINE__, __FILE__)

    with similar for realloc (and make free do GC_free).

    Then run the proggy, redirecting stderr through a simple python script: (leading spaces have been replaced with underscores since slashdot doesn't do PRE)

    import sys

    a={}

    for line in sys.stdin.readlines():
    __line=line.strip()
    __num=line[line.find("0x"):]
    __try:
    ____num=num[0: num.index(" ")]
    __except:
    ____pass

    __if line[1]=="i":
    ____a[num]=line
    __else:
    ____print "Leaked object: "+a[num]

    When I run my program this way I get the following output:

    Leaked object: Line 43 of leak_stuff.c/(): 0x806efe0
    Leaked object: Line 43 of leak_stuff.c/(): 0x806eff0
    Leaked object: Line 55 of leak_stuff.c/(): 0x806dfd8

    Which tells me which lines to look for the initial allocations of leaked objects at.

    The garbage-collecting malloc is really cool; it's at:

    http://www.hpl.hp.com/personal/Hans_Boehm/gc/

    for now, but rumor has it that gcc will become the official source for it at some point (it's needed for the Java compiler).

    Sumner

    --
    rage, rage against the dying of the light
    1. Re:Memory leak detection by d^2b · · Score: 4, Informative

      dmalloc (www.dmalloc.com) seems to work pretty well for finding memory leaks. It is distributed under a BSDish
      license.

      Compiles and runs out of the box on an alpha
      running Linux.

      GUI? uh no. It has a nifty command line utility to control logging etc...