NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: debugging a memory leak



On Fri, 20 May 2016, Manuel Bouyer wrote:
> what tools do we have on NetBSD to find a memory leak in a userland 
> program (actually OpenCPN - which is a large C++ program with dynamic 
> libraries and uses dlopen()) ?

Manuel, I'm guessing you are a much better C programmer than I, but I can 
relate what I use. I do three different things:

1. If it'll compile on Linux, I'll test it with valgrind and just apply 
the results on the NetBSD side. 

2. ElectricFence, but I doubt it'd work with libs dlopen()'d. Then again, 
if you used it with LD_PRELOAD you might be able to pre-empt the symbols 
even in the dynamic libs (in theory). 

3. I created a cheeseball reference counter similar to the one in glib by 
just wrappering malloc(). It just add/drops/prints a linked list of 
structs which are entries I'm tracking. When everything is working 
perfectly, I remove it. Voila clean memory management without krufty 
GC overhead! 

> The memory usage of the process is slowy growing, until the systems gets 
> out of ram/swap and kills it (on my evbarm which has no swap it takes 
> about 2 days).

My guess (which ain't worth much, take it with a grain of salt) you'd find 
it pretty darn fast with valgrind. It's never failed me, but it's limited 
to Linux, Darwin, and Solaris.

-Swift



Home | Main Index | Thread Index | Old Index