atk-adaptor: plug some refcount leaks
authorCosimo Cecchi <cosimoc@gnome.org>
Thu, 13 Sep 2012 17:37:50 +0000 (13:37 -0400)
committerCosimo Cecchi <cosimoc@gnome.org>
Thu, 13 Sep 2012 20:38:32 +0000 (16:38 -0400)
cache->add_traversal holds GObject references, so when we remove/pop
items from it, we should also drop the reference, unless it's transfered
to another queue.

https://bugzilla.gnome.org/show_bug.cgi?id=683979

atk-adaptor/accessible-cache.c

index afaedb0..3a30b51 100644 (file)
@@ -180,7 +180,10 @@ remove_object (GObject * source, GObject * gobj, gpointer data)
       g_hash_table_remove (cache->objects, gobj);
     }
   else
-    g_queue_remove (cache->add_traversal, gobj);
+    {
+      g_queue_remove (cache->add_traversal, gobj);
+      g_object_unref (gobj);
+    }
 }
 
 static void
@@ -277,12 +280,14 @@ add_pending_items (gpointer data)
   while (!g_queue_is_empty (cache->add_traversal))
     {
       AtkStateSet *set;
-      
+
+      /* cache->add_traversal holds a ref to current */
       current = g_queue_pop_head (cache->add_traversal);
       set = atk_object_ref_state_set (current);
 
       if (set && !atk_state_set_contains_state (set, ATK_STATE_TRANSIENT))
         {
+          /* transfer the ref into to_add */
          g_queue_push_tail (to_add, current);
           if (!spi_cache_in (cache, G_OBJECT (current)) &&
               !atk_state_set_contains_state  (set, ATK_STATE_MANAGES_DESCENDANTS) &&
@@ -291,6 +296,11 @@ add_pending_items (gpointer data)
               append_children (current, cache->add_traversal);
             }
         }
+      else
+        {
+          /* drop the ref for the removed object */
+          g_object_unref (current);
+        }
 
       if (set)
         g_object_unref (set);