Check that we have a valid path when emitting a signal
[platform/core/uifw/at-spi2-atk.git] / atk-adaptor / adaptors / cache-adaptor.c
index e221920..8bd49af 100644 (file)
@@ -80,8 +80,6 @@ append_cache_item (AtkObject * obj, gpointer data)
   const char *name, *desc;
   dbus_uint32_t role;
 
-  g_object_ref (G_OBJECT (obj));
-
   set = atk_object_ref_state_set (obj);
   {
     AtkObject *application, *parent;
@@ -216,11 +214,16 @@ append_cache_item (AtkObject * obj, gpointer data)
   }
   dbus_message_iter_close_container (iter_array, &iter_struct);
   g_object_unref (set);
-  g_object_unref (obj);
 }
 
 /*---------------------------------------------------------------------------*/
 
+static void
+ref_accessible_hf (gpointer key, gpointer obj_data, gpointer data)
+{
+  g_object_ref (key);
+}
+
 /* For use as a GHFunc */
 static void
 append_accessible_hf (gpointer key, gpointer obj_data, gpointer data)
@@ -230,6 +233,13 @@ append_accessible_hf (gpointer key, gpointer obj_data, gpointer data)
     append_cache_item (ATK_OBJECT (key), data);
 }
 
+static void
+add_to_list_hf (gpointer key, gpointer obj_data, gpointer data)
+{
+  GSList **listptr = data;
+  *listptr = g_slist_prepend (*listptr, key);
+}
+
 /*---------------------------------------------------------------------------*/
 
 static void
@@ -267,7 +277,9 @@ emit_cache_add (SpiCache *cache, GObject * obj)
       DBusMessageIter iter;
 
       dbus_message_iter_init_append (message, &iter);
+      g_object_ref (accessible);
       append_cache_item (accessible, &iter);
+      g_object_unref (accessible);
 
       dbus_connection_send (spi_global_app_data->bus, message, NULL);
 
@@ -291,6 +303,7 @@ impl_GetItems (DBusConnection * bus, DBusMessage * message, void *user_data)
 {
   DBusMessage *reply;
   DBusMessageIter iter, iter_array;
+  GSList *pending_unrefs = NULL;
 
   if (bus == spi_global_app_data->bus)
     spi_atk_add_client (dbus_message_get_sender (message));
@@ -300,7 +313,10 @@ impl_GetItems (DBusConnection * bus, DBusMessage * message, void *user_data)
   dbus_message_iter_init_append (reply, &iter);
   dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY,
                                     SPI_CACHE_ITEM_SIGNATURE, &iter_array);
+  spi_cache_foreach (spi_global_cache, ref_accessible_hf, NULL);
   spi_cache_foreach (spi_global_cache, append_accessible_hf, &iter_array);
+  spi_cache_foreach (spi_global_cache, add_to_list_hf, &pending_unrefs);
+  g_slist_free_full (pending_unrefs, g_object_unref);
   dbus_message_iter_close_container (&iter, &iter_array);
   return reply;
 }