1 https://bugzilla.gnome.org/show_bug.cgi?id=556515 - g_object_unref race condition
4 diff --git /tmp/gobject.c glib-2.21.6/gobject/gobject.c
5 index 454d8c2..75f479c 100644
7 +++ glib-2.21.6/gobject/gobject.c
8 @@ -2380,11 +2380,12 @@ g_object_unref (gpointer _object)
9 old_ref = g_atomic_int_get (&object->ref_count);
12 + gboolean do_toggle_ref_notify = (old_ref == 2 && OBJECT_HAS_TOGGLE_REF (object));
13 if (!g_atomic_int_compare_and_exchange ((int *)&object->ref_count, old_ref, old_ref - 1))
14 goto retry_atomic_decrement1;
16 /* if we went from 2->1 we need to notify toggle refs if any */
17 - if (old_ref == 2 && OBJECT_HAS_TOGGLE_REF (object))
18 + if (do_toggle_ref_notify)
19 toggle_refs_notify (object, TRUE);
22 @@ -2397,11 +2398,12 @@ g_object_unref (gpointer _object)
23 old_ref = g_atomic_int_get ((int *)&object->ref_count);
26 + gboolean do_toggle_ref_notify = (old_ref == 2 && OBJECT_HAS_TOGGLE_REF (object));
27 if (!g_atomic_int_compare_and_exchange ((int *)&object->ref_count, old_ref, old_ref - 1))
28 goto retry_atomic_decrement2;
30 /* if we went from 2->1 we need to notify toggle refs if any */
31 - if (old_ref == 2 && OBJECT_HAS_TOGGLE_REF (object))
32 + if (do_toggle_ref_notify)
33 toggle_refs_notify (object, TRUE);