GNOME Bugzilla – Bug 311043
Memory leaks (and potential infinite loops) when using G_ERRORCHECK_MUTEXES
Last modified: 2006-05-10 00:45:20 UTC
With some multi-threading implementations (such as pthreads), g_private_set() should not be called from a thread-specific data destructor. From pthread_setspecific(3): "the pthread_setspecific() function may be called from a thread-specific data destructor function, however this may result in lost storage or infinite loops". However, when G_ERRORCHECK_MUTEXES is used: - g_thread_cleanup() (the tls data destructor) may call G_LOCK() - G_LOCK() ends up in g_mutex_lock_errorcheck_impl() - g_mutex_lock_errorcheck_impl() calls g_thread_self() - g_thread_self() may call g_private_set() ---> memory leak and/or infinite loop The attached patch solves the issue by using g_thread_functions_for_glib_use.thread() directly in the G_ERRORCHECK_MUTEXES code, thus bypassing the potential g_private_set() calls.
Created attachment 49478 [details] [review] the fix
s/g_thread_functions_for_glib_use.thread()/g_thread_functions_for_glib_use.thread_self()/
2006-05-09 Sebastian Wilhelmi <wilhelmi@google.com> * glib/gthreadinit.h: Renamed to glib/gthreadprivate.h and moved system thread identifier comparision and assignment macros from glib/gthread.c to glib/gthreadprivate.h. * glib/Makefile.am, glib/gatomic.c, glib/gconvert.c, glib/gmain.c, glib/gmem.c, glib/gmessages.c, glib/grand.c, glib/gslice.c, glib/gthread.c, glib/gutils.c, gthread/gthread-impl.c: Use glib/gthreadprivate.h instead of glib/gthreadinit.h. * gthread/gthread-impl.c: Use GSystemThread instead of GThread for owner determination. (#311043, jylefort@FreeBSD.org) * tests/Makefile.am, tests/errorcheck-mutex-test: New test program to test for all checked violations.