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 391278 - (late-gthread-init) g_thread_init() called too late, possibly causing memory corruptions
(late-gthread-init)
g_thread_init() called too late, possibly causing memory corruptions
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gstreamer (core)
git master
Other Linux
: Normal critical
: 0.10.12
Assigned To: GStreamer Maintainers
GStreamer Maintainers
: 354483 366359 370974 378525 379690 382294 382885 386847 389421 405867 430407 435337 440386 440387 467556 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2006-12-31 12:22 UTC by Christian Persch
Modified: 2007-08-17 11:16 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Init GLib threads in constructor, and warn if that's not possible and threads haven't been initialised elsewhere (3.03 KB, patch)
2007-01-02 11:21 UTC, Tim-Philipp Müller
rejected Details | Review

Description Christian Persch 2006-12-31 12:22:27 UTC
With glib trunk, I get this critical warning when running gst-inspect-0.10, gst-typefind-0.10 etc:

***MEMORY-WARNING***: gst-launch-0.10[16931]: GSlice: g_thread_init() must be called before all other GLib functions; memory corruption due to late invocation of g_thread_init() has been detected; this program is likely to crash, leak or unexpectedly abort soon...

glib svn trunk, gstreamer/gst-plugins-* cvs HEAD
Comment 1 Tim-Philipp Müller 2006-12-31 16:26:44 UTC
If this is true, and I understand it correctly, this would not only seem to be an ABI break on glib's part [*], but also completely defeat the purpose of doing library initialisations indirectly via GOption, at least for libraries that use threads internally.

The problem seems to come from g_option_context_add_group(), which creates GList nodes, which internally uses GSlice.

So basically all applications initialising GStreamer via GOption have to be changed to initialise the GLib thread system first (if gst_init() is used directly, we do the call to g_thread_init() first and can only pray that the application hasn't used any other GLib/Gtk functions first).


[*] However, the GLib API manual says "g_thread_init() must not be called directly or indirectly as a callback from GLib.", and I guess that includes GOption callbacks, so arguably we've been using it incorrectly all along ...
Comment 2 Tim-Philipp Müller 2007-01-02 11:21:45 UTC
Created attachment 79172 [details] [review]
Init GLib threads in constructor, and warn if that's not possible and threads haven't been initialised elsewhere

Not sure what to do about this. Two possibilities come to mind:

 1) Change our init semantics. This probably means most applications
    initialising GStreamer via GOption need to be changed/fixed.

 2) Try to initialise the threading system in a constructor and issue
    a warning in cases where that's not possible (ie. where the compiler
    does not support it or we don't have special code for that compiler)
    and where the threading system hasn't been initialised by the time
    the application calls gst_init_get_option_group(). This would only
    affect applications that link against a GStreamer that hasn't been
    compiled with GCC or Forte and that use GOption for initing and
    haven't inited the threads system otherwise yet. And even for those
    cases there's not really a functional regression, we just init the
    thread system as early as possible, issue a warning and keep our
    our fingers crossed.

Can anyone think of a better option?

Attached patch implements option 2).
Comment 3 Tim-Philipp Müller 2007-01-05 16:38:24 UTC
Related discussion on gtk-devel-list:
http://mail.gnome.org/archives/gtk-devel-list/2007-January/msg00005.html


Even if this gets resolved in GLib in future, it still affects all GStreamer appplications using GLib-2.10.x and GLib-2.12.x.

Not using the constructor hack, for three reasons:

 - it breaks applications which do g_thread_init (NULL) unconditionally
   first thing in main(), such as totem

 - it hides the problem on most systems, so applications are much less
   likely to get fixed

 - application authors and people deploying applications should be
   aware the problem exists for current and previous versions of
   GStreamer and GLib


Committed the following for now, I think it's the best we can do:

  2007-01-05  Tim-Philipp Müller  <tim at centricular dot net>

        * gst/gst.c: (gst_init_get_option_group), (gst_init_check),
        (init_pre):
          Call g_thread_init() first thing in gst_init() / gst_check_init().
          When initialisation is done via gst_init_get_option_group() and
          GOption parsing, issue a warning if the GLib thread system has not
          been initialised yet by the time gst_init_get_option_group() is
          called, as it's quite likely other GLib functions such as
          g_option_context_new() have been called already then, and
          g_thread_init() must be called before any other GLib function. The
          application in question must be fixed in that case, since memory
          corruption might happen otherwise.
          We issue the warning because even if the GLib folks decide to work
          around the problem on their end in future, this is still an issue
          with all GLib versions >= 2.10.0, so we should warn until we depend
          on a GLib version we know to be safe.
          Closes bug #391278.

Comment 4 Tim-Philipp Müller 2007-01-08 22:41:59 UTC
*** Bug 354483 has been marked as a duplicate of this bug. ***
Comment 5 Tim-Philipp Müller 2007-01-08 22:42:26 UTC
*** Bug 379690 has been marked as a duplicate of this bug. ***
Comment 6 Tim-Philipp Müller 2007-01-08 22:43:07 UTC
*** Bug 386847 has been marked as a duplicate of this bug. ***
Comment 7 Tim-Philipp Müller 2007-01-09 09:35:27 UTC
*** Bug 366359 has been marked as a duplicate of this bug. ***
Comment 8 Tim-Philipp Müller 2007-01-11 18:08:53 UTC
*** Bug 370974 has been marked as a duplicate of this bug. ***
Comment 9 Tim-Philipp Müller 2007-01-11 18:12:18 UTC
*** Bug 378525 has been marked as a duplicate of this bug. ***
Comment 10 Tim-Philipp Müller 2007-01-11 18:17:06 UTC
*** Bug 382294 has been marked as a duplicate of this bug. ***
Comment 11 Tim-Philipp Müller 2007-01-16 12:06:25 UTC
*** Bug 389421 has been marked as a duplicate of this bug. ***
Comment 12 Tim-Philipp Müller 2007-02-01 19:19:47 UTC
*** Bug 382885 has been marked as a duplicate of this bug. ***
Comment 13 Mariano Suárez-Alvarez 2007-02-09 00:58:23 UTC
*** Bug 405867 has been marked as a duplicate of this bug. ***
Comment 14 palfrey 2007-04-30 14:46:43 UTC
*** Bug 430407 has been marked as a duplicate of this bug. ***
Comment 15 palfrey 2007-05-03 12:46:17 UTC
*** Bug 435337 has been marked as a duplicate of this bug. ***
Comment 16 palfrey 2007-05-22 12:58:35 UTC
*** Bug 440386 has been marked as a duplicate of this bug. ***
Comment 17 palfrey 2007-05-22 12:58:37 UTC
*** Bug 440387 has been marked as a duplicate of this bug. ***
Comment 18 palfrey 2007-08-17 11:16:24 UTC
*** Bug 467556 has been marked as a duplicate of this bug. ***