On Tue, Aug 17, 2010 at 03:05:11PM +0100, Sad Clouds wrote: > On Mon, 16 Aug 2010 13:57:14 PDT > Stephan Ferraro <step...@ferraro.net> wrote: > > > I'm currently searching for an electric fence malloc. I read > > something that there exists a dmalloc. Is there a documentation how > > to use it and where to get it on OpenSolaris? > > Well, from my experience memory leaks can come from all sorts of > places, not just malloc(). For example, when writing heavily > multi-threaded code, I would occasionally miss a call to > pthread_mutex_destroy(), etc., which resulted in memory leaks. > > You can write a small library which tracks every call to: > > malloc() > calloc() > realloc() > free()
libumem does the above for you (man libumem and umem_debug). > pthread_mutex_init() > pthread_mutex_destroy() > pthread_mutex_lock() > pthread_mutex_trylock() > pthread_mutex_unlock() > > pthread_rwlock_init() > pthread_rwlock_destroy() > pthread_rwlock_rdlock() > pthread_rwlock_tryrdlock() > pthread_rwlock_wrlock() > pthread_rwlock_trywrlock() > pthread_rwlock_unlock() > > So the library not only tracks memory leaks, but also when threads fail > to call lock destroy functions, or when locking/unlocking already > locked/unlocked lock. dtrace can trace the lock calls and plockstat can provide lock stats for user space programs. truss can also trace user space function calls but has higher overhead than dtrace. In addition the SunStudio C dev. tools includes a static lock analyzer called lock_lint. I suggest trying those first before going to the trouble of writing a library. -- Will Fiveash Oracle http://opensolaris.org/os/project/kerberos/ Sent using mutt, a sweet text based e-mail app: http://www.mutt.org/ _______________________________________________ opensolaris-code mailing list opensolaris-code@opensolaris.org http://mail.opensolaris.org/mailman/listinfo/opensolaris-code