summaryrefslogtreecommitdiff
path: root/recipes/glib-2.0/bug-556515.patch
blob: 0af15a6f8f5915348c3fd8e2f562f2a8fad43d45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
https://bugzilla.gnome.org/show_bug.cgi?id=556515 - g_object_unref race condition


diff --git /tmp/gobject.c glib-2.21.6/gobject/gobject.c
index 454d8c2..75f479c 100644
--- /tmp/gobject.c
+++ glib-2.21.6/gobject/gobject.c
@@ -2380,11 +2380,12 @@ g_object_unref (gpointer _object)
   old_ref = g_atomic_int_get (&object->ref_count);
   if (old_ref > 1)
     {
+      gboolean do_toggle_ref_notify = (old_ref == 2 && OBJECT_HAS_TOGGLE_REF (object));
       if (!g_atomic_int_compare_and_exchange ((int *)&object->ref_count, old_ref, old_ref - 1))
 	goto retry_atomic_decrement1;
 
       /* if we went from 2->1 we need to notify toggle refs if any */
-      if (old_ref == 2 && OBJECT_HAS_TOGGLE_REF (object))
+      if (do_toggle_ref_notify)
 	toggle_refs_notify (object, TRUE);
     }
   else
@@ -2397,11 +2398,12 @@ g_object_unref (gpointer _object)
       old_ref = g_atomic_int_get ((int *)&object->ref_count);
       if (old_ref > 1)
         {
+          gboolean do_toggle_ref_notify = (old_ref == 2 && OBJECT_HAS_TOGGLE_REF (object));
           if (!g_atomic_int_compare_and_exchange ((int *)&object->ref_count, old_ref, old_ref - 1))
 	    goto retry_atomic_decrement2;
 
           /* if we went from 2->1 we need to notify toggle refs if any */
-          if (old_ref == 2 && OBJECT_HAS_TOGGLE_REF (object))
+          if (do_toggle_ref_notify)
 	    toggle_refs_notify (object, TRUE);
           
 	  return;