Re: idea for catching memory leaks

Rogier Wolff (R.E.Wolff@bitwizard.nl)
Tue, 28 Oct 1997 09:25:59 +0100 (MET)


C. Scott Ananian wrote:
>
> > From: Nathan Bryant <nathan@nbryan71.dorm.usm.maine.edu>
> > Date: Fri, 24 Oct 1997 19:09:40 -0400 (EDT)
> > Subject: idea for catching memory leaks
> >
> > here's a simple idea for catching memory leaks: modify kmalloc() so that
> > it examines its call frame and tags each chunk of memory with the address
> > kmalloc() was called from. i'd be surprised if nobody has thought of
> > something like this before; has anyone done patches for that sort of
> > thing?

I wrote this patch around '93 just after my malloc made it into the
kernel. I've redone it twice to match current kernels.

> Might I suggest adding a 'magic sequence' bracketing your tags as well?
> Then a user-mode binary grep through /dev/kmem could identify potential
> trouble areas. Not 100% accurate, of course, but should grab any
> significant growing leaks due to a single source.

My patch simply has a /proc/debug-kmalloc file. It contains all
"currently in use" memory blobs, including the number of bytes requested,
the file name where the alloc was done, the line number and the first 10
bytes of the allocated region......

Roger.

-- 
** R.E.Wolff@BitWizard.nl ** +31-15-2137555 ** http://www.BitWizard.nl/ **
Florida -- A 39 year old construction worker woke up this morning when a
109-car freight train drove over him. According to the police the man was 
drunk. The man himself claims he slipped while walking the dog. 080897