Re: Memory Leak

From: M. Warner Losh (imp_at_bsdimp.com)
Date: 05/23/04

  • Next message: Jason Slagle: "bge machines..."
    Date: Sat, 22 May 2004 22:30:42 -0600 (MDT)
    To: kientzle@freebsd.org
    
    

    In message: <40AFA163.4020109@freebsd.org>
                Tim Kientzle <kientzle@freebsd.org> writes:
    : 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.

    Any suggestions for leak detectors that work in real-time or in
    response to some external signal? In a threaded application would be
    ideal.

    I've hacked malloc to add the stack traceback to the utrace info
    that's output by malloc. However, for applications that run for days,
    and tend to allocate and free a lot of memory, you gotta have lots of
    local storage. The restrictions in the kernel that requires this to
    be a real file makes it harder.

    Also, there's a difference between what's in use and what is leaking..

    Warner
    _______________________________________________
    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: Jason Slagle: "bge machines..."

    Relevant Pages

    • Re: Memory Leak
      ... > memory leak in your programs? ... I've had pretty good luck with dmalloc from ports. ... malloc in bsdtar, with some concrete performance ... heap-allocated buffers to stack-allocated buffers ...
      (freebsd-hackers)
    • Re: free() performance question
      ... malloc a new space ... and then free the originial two buffers. ... I put timer on each step. ... for an standard C implementation for DJGPP and others. ...
      (comp.lang.c)
    • Re: Null pointers in C---spec (N869) trouble, was What computer language is used a lot in the IT ind
      ... malloc() itself can *not* be written in Standard ... for the simple reason that mallocis required (by the Standard) ... The pointers and perhaps even the integers ... and integers in the "D" registers. ...
      (comp.lang.c)
    • Re: Null pointers in C---spec (N869) trouble, was What computer language is used a lot in the IT ind
      ... malloc() itself can *not* be written in Standard ... for the simple reason that mallocis required (by the Standard) ... The pointers and perhaps even the integers ... and integers in the "D" registers. ...
      (comp.programming)
    • Re: malloc under linux
      ... It means what it says, i.e., even if malloc returns a non-null ... memory might not actually be allocated. ... Standard even when some other process is killed and sufficient memory is ... I can't see how the Standard does not permit lazy allocation, ...
      (comp.lang.c)