Re: Memory Leak

From: Tim Kientzle (kientzle_at_freebsd.org)
Date: 05/22/04

  • Next message: Cole: "Pthread_create and memory issues."
    Date: Sat, 22 May 2004 11:52:19 -0700
    To: Cole <cole@opteqint.net>
    
    

    Cole wrote:
    > Hey
    >
    > I just wanted to know what programs any of you have used to track down a
    > memory leak in your programs?
    > Also wondering if there is maybe a good tutorial on the subject under
    > FreeBSD or even linux if possible.
    >
    > Im running FreeBSD 4.9 so just looking for something try to help me track it
    > down.
    >
    > Unless there is someone willing to help me with this since ive never really
    > had to do anything like this, else i can easily read something, just kinda
    > need to know a good memory tracing program or something of the sorts.

    I've had pretty good luck with dmalloc from ports.

    Just add
       #include <dmalloc.h>
    to the *END* of your includes and link against
    the dmalloc library. The tracing is controlled
    by environment variables; you can use the 'dmalloc'
    program to help set those. The one problem I've had
    is that dmalloc.h redefines some standard functions,
    which can cause gcc to complain. I've locally
    modified some of the standard system headers to
    not define malloc/free/strdup/calloc/realloc/etc
    if DMALLOC is defined. It's a hack, but it works.

    dmalloc also gives good statistics about malloc
    usage. I've used it to identify over-use of
    malloc in bsdtar, with some concrete performance
    improvements. (For example, by switching from
    heap-allocated buffers to stack-allocated buffers
    or by re-using buffers to avoid repeated
    malloc/free calls.)

    The FreeBSD standard malloc also has some nice debugging
    features. I've found that switching between dmalloc
    and the libc malloc helps a lot, as each catches
    different sorts of problems.

    Tim Kientzle

    _______________________________________________
    freebsd-hackers@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
    To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"


  • Next message: Cole: "Pthread_create and memory issues."

    Relevant Pages

    • Re: Memory Leak
      ... I've had pretty good luck with dmalloc from ports. ... is that dmalloc.h redefines some standard functions, ... malloc in bsdtar, with some concrete performance ... heap-allocated buffers to stack-allocated buffers ...
      (freebsd-hackers)
    • Re: Arraym malloc() and free() question
      ... > I have a question regarding malloc and free. ... int main ... this produces clearly a memory leak as the reference to the memoty ... The second time I allocate ...
      (comp.lang.c)
    • Re: regarding free
      ... would it be a memory leak? ... You effectively discard the pointer returned by malloc(), ... Typically also, however, development environments include ...
      (comp.lang.c)
    • Re: malloc and memory leaks
      ... | This is the function malloc_m() that should be like mallocbut it ... | should find memory leak, and over bound writing in arrays. ...
      (alt.lang.asm)
    • Re: malloc and memory leaks
      ... > This is the function malloc_m() that should be like mallocbut it ... > should find memory leak, and over bound writing in arrays. ...
      (alt.lang.asm)