'pthread_mutex_destroy' memory leak report

Milan Gardian mg@tatramed.sk
Tue Sep 7 09:31:00 GMT 1999


Dear pthreads colleagues,

Purify has recently reported to me a memory leak that originated in my
pthread mutex adapter class. I have investigated deeper into the code and
here are my findings:

===
file: pthreads_dir/mutex.c
line: 91
func: pthread_mutex_init

  mx = (pthread_mutex_t) calloc(1, sizeof(*mx));

---
file: pthreads_dir/mutex.c
line: ?
func: pthread_mutex_destroy

No corresponding free (to the calloc above).

===

My advice is to insert 'free(mx)' call into 'pthread_mutex_destroy' function
before returning status to the caller (if mx has reasonable value, of
course) as follows:

===
file: pthreads_dir/mutex.c
line: 197 - 204
func: pthread_mutex_destroy

  if (result == 0)
    {
      mx->mutex = 0;
      free (mx);
      *mutex = NULL;
    }

  return(result);
===

(Or am I missing something?)
Hope this helps,
Best regards,
	Milan G.



More information about the Pthreads-win32 mailing list