Don't cache objects that return NULL when their state set is queried
[platform/core/uifw/at-spi2-atk.git] / atk-adaptor / accessible-cache.c
index 4d5cdb3..20796d5 100644 (file)
@@ -179,6 +179,8 @@ remove_object (GObject * source, GObject * gobj, gpointer data)
       g_signal_emit (cache, cache_signals [OBJECT_REMOVED], 0, gobj);
       g_hash_table_remove (cache->objects, gobj);
     }
+  else
+    g_queue_remove (cache->add_traversal, gobj);
 }
 
 static void
@@ -279,7 +281,7 @@ add_pending_items (gpointer data)
       current = g_queue_pop_head (cache->add_traversal);
       set = atk_object_ref_state_set (current);
 
-      if (!atk_state_set_contains_state (set, ATK_STATE_TRANSIENT))
+      if (set && !atk_state_set_contains_state (set, ATK_STATE_TRANSIENT))
         {
          g_queue_push_tail (to_add, current);
           if (!spi_cache_in (cache, G_OBJECT (current)) &&
@@ -290,7 +292,8 @@ add_pending_items (gpointer data)
             }
         }
 
-      g_object_unref (set);
+      if (set)
+        g_object_unref (set);
     }
 
   while (!g_queue_is_empty (to_add))
@@ -318,7 +321,7 @@ child_added_listener (GSignalInvocationHint * signal_hint,
                       const GValue * param_values, gpointer data)
 {
   SpiCache *cache = spi_global_cache;
-
+  gboolean child_needs_ref = TRUE;
   AtkObject *accessible;
   AtkObject *child;
 
@@ -351,10 +354,12 @@ child_added_listener (GSignalInvocationHint * signal_hint,
           child = g_value_get_pointer (param_values + 2);
 
           if (!ATK_IS_OBJECT (child))
-           {
-             child = atk_object_ref_accessible_child (accessible, index);
-           }
-          g_object_ref (child);
+            {
+              child = atk_object_ref_accessible_child (accessible, index);
+              child_needs_ref = FALSE;
+            }
+          if (child_needs_ref)
+            g_object_ref (child);
           g_queue_push_tail (cache->add_traversal, child);
 
           if (cache->add_pending_idle == 0)