On Thu, Mar 30, 2006 at 06:49:25PM -0800, Lingyun Li wrote: > Hi, > > I'm on Solaris 10 3/05 using Sun Studio 11 C compiler. I'm using > ::findleaks to search for memory leaks. I found somehow ::findleaks > can't find all obvious leaks. I made small a test program below which > contains three leaks to illustrate the problem. Can anyone tell me > why? Thanks.
Because pointers to the buffers may still be on the stack. How many leaks you see will depend on your compiler options, instruction set architecture, etc. Cheers, - jonathan > test program: leak.c > > #include <stdio.h> > #include <stdlib.h> > #include <unistd.h> > > void mysleep() > { > printf("sleeping for 60 seconds to allow gcore\n"); > sleep(60); > } > > void *f3() > { > return malloc(400); > } > > void f2() > { > char *p; > p=malloc(3330); > } > > void main() > { > f2(); > f2(); > f3(); > mysleep(); > } > > I compiled it using "cc -g -o leak leak.c". Blow is what did to reproduce the > problem. > > 1) # UMEM_DEBUG=default; LD_PRELAOD=libumem.so.1; export UMEM_DEBUG LD_PRELOAD > 2) # leak & > sleeping for 60 seconds to allow gcore > [1] 23724 > 3) # gcore 23724 > gcore: core.23724 dumped > 4) # mdb core.23724 > Loading modules: [ libumem.so.1 libc.so.1 ld.so.1 ] > > ::findleaks -dv > findleaks: using cached results (-f will force a full run) > CACHE LEAKED BUFCTL CALLER > 00033008 1 00043c20 f2+4 > ---------------------------------------------------------------------- > Total 1 buffer, 4096 bytes > > umem_alloc_4096 leak: 1 buffer, 4096 bytes > ADDR BUFADDR TIMESTAMP THREAD > CACHE LASTLOG CONTENTS > 43c20 3d200 e8e332cc57f2 1 > 33008 0 0 > libumem.so.1`umem_cache_alloc+0x13c > libumem.so.1`umem_alloc+0x60 > libumem.so.1`malloc+0x28 > f2+4 > main+0xc > _start+0x108 > > > > > ::findleaks only found 1 leak but actually there are 3 leaks. Anyone can > explain why and how to find all leaks? Thank you. > > -- Hunter > > > This message posted from opensolaris.org > _______________________________________________ > mdb-discuss mailing list > mdb-discuss at opensolaris.org -- Jonathan Adams, Solaris Kernel Development