On Thursday 30 March 2006 1:25 pm, Claus Assmann wrote:
> On Thu, Mar 30, 2006, Ted Unangst wrote:
> 
> > particular to pthreads, if you are using mutexes or somesuch on the
> > stack, you will leak memory.  (the lock on the stack is just a
> > pointer, it gets allocated on first use).
> 
> All mutexes are part of structures that are allocated via malloc().
> Would those leak memory too (even if pthread_mutex_destroy() is
> called)? The application (it's the sendmail X address resolver)
> uses a new mutex/condition variable for every request in the test
> that triggers the leaks.
> 
> Thanks for your answer!

I recently went through a similar exercise looking for
leaks in the jvm thread creation and destruction code.
The process is simple but tedious. Build a debug version
of libc, libpthread and your application. Put a break
point on malloc, realloc & free. When malloc and realloc
are hit, do the finish gdb command and note the returned
address on a pad and where it was called from. When free is
called cross off the matching address from the list. Whatever
is left is the source of your leak.

There are things you could do help the process along, like
using gdb's 'commands' feature. If you suspect the pthreads
library is leaking you could place break points at the
malloc / realloc / free calls that your application hits in
pthreads (ie break at the calls to malloc in the pthread code,
not at malloc itself). 

-Kurt

Reply via email to