After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 311043 - Memory leaks (and potential infinite loops) when using G_ERRORCHECK_MUTEXES
Memory leaks (and potential infinite loops) when using G_ERRORCHECK_MUTEXES
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gthread
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2005-07-20 18:12 UTC by Jean-Yves Lefort
Modified: 2006-05-10 00:45 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
the fix (8.87 KB, patch)
2005-07-20 18:13 UTC, Jean-Yves Lefort
none Details | Review

Description Jean-Yves Lefort 2005-07-20 18:12:39 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.
Comment 1 Jean-Yves Lefort 2005-07-20 18:13:37 UTC
Created attachment 49478 [details] [review]
the fix
Comment 2 Jean-Yves Lefort 2005-07-20 18:15:41 UTC
s/g_thread_functions_for_glib_use.thread()/g_thread_functions_for_glib_use.thread_self()/
Comment 3 Sebastian Wilhelmi 2006-05-10 00:45:20 UTC
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.