[at-spi2-atk/gnome-3-2] In GetItems, unref objects in two passes
- From: Mike Gorse <mgorse src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [at-spi2-atk/gnome-3-2] In GetItems, unref objects in two passes
- Date: Sat, 26 Nov 2011 21:52:26 +0000 (UTC)
commit ed6684fc8ad7830d7362bb2c8c24ce3bb45e9d6c
Author: Mike Gorse <mgorse novell com>
Date: Sat Nov 26 15:50:55 2011 -0600
In GetItems, unref objects in two passes
It is dangerous to unref cache objects inside a g_hash_table_foreach,
since, if the object is finalized, it will be removed, which can cause
problems with the iterator. Instead, make a GSList of the objects to
unref, then use this GSList to unref.
atk-adaptor/adaptors/cache-adaptor.c | 9 ++++++---
1 files changed, 6 insertions(+), 3 deletions(-)
---
diff --git a/atk-adaptor/adaptors/cache-adaptor.c b/atk-adaptor/adaptors/cache-adaptor.c
index 4f647a1..8bd49af 100644
--- a/atk-adaptor/adaptors/cache-adaptor.c
+++ b/atk-adaptor/adaptors/cache-adaptor.c
@@ -234,9 +234,10 @@ append_accessible_hf (gpointer key, gpointer obj_data, gpointer data)
}
static void
-unref_accessible_hf (gpointer key, gpointer obj_data, gpointer data)
+add_to_list_hf (gpointer key, gpointer obj_data, gpointer data)
{
- g_object_unref (key);
+ GSList **listptr = data;
+ *listptr = g_slist_prepend (*listptr, key);
}
/*---------------------------------------------------------------------------*/
@@ -302,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));
@@ -313,7 +315,8 @@ impl_GetItems (DBusConnection * bus, DBusMessage * message, void *user_data)
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, unref_accessible_hf, NULL);
+ 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;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]