From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alastair Hume To: "'pthreads-win32@sources.redhat.com'" Subject: RE: Memory leak in pthread_setcanceltype()? Date: Thu, 28 Sep 2000 09:20:00 -0000 Message-id: <9114362C5989D311928C005004A82520391AC0@lethe.csl.co.uk> X-SW-Source: 2000/msg00113.html > I don't know for a fact, but I'd be leary about calling pthread_mutex_destroy() > on a mutex not initialized with pthread_mutex_init() (i.e. initialied with > PTHREAD_MUTEX_INITIALIZER). It feels like free()ing a pointer to a char array > allocated on the stack to me. I certainly wouldn't depend on calling > pthread_mutex_destroy() on a mutex not initialized via pthread_mutex_init() to > be portable. > From the sound of it, to be safe I'd personally recommend avoiding the > PTHREAD_MUTEX_INITIALIZER and use pthread_mutex_init() to initialize and > pthread_mutex_destroy() to destroy. That's what I've done now and the memory leaks have gone away. Seems fairly sensible to me and I'm happy with this. My original implementation was done after reading Butenhof's "Programming with POSIX Threads" (Addison-Wesley) which said on page 51, "You do not need to destroy a mutex that was statically initialized using the PTHREAD_MUTEX_INITIALIZER macro." Thanks to all who helped, Ally Hume