summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Gorse <mgorse@novell.com>2011-05-17 14:01:04 -0500
committerMike Gorse <mgorse@novell.com>2011-05-17 14:01:04 -0500
commitdca58979dd3d29b363853dcfecc40effa8314b36 (patch)
treeadb680d22c5bbe310c01a9a3e860f0c84f96ea4c
parent1c1f423c14d84356eb37f364a72811f0315b2bd0 (diff)
downloadat-spi2-core-dca58979dd3d29b363853dcfecc40effa8314b36.tar.gz
In atspi_match_rule_get_attributes, copy the hash rather than ref it
It is not safe to ref a hash marked (transfer none) and expect its elements to remain, since the caller will assume that it owns the elements and may deallocate them (this is done by pygobject). It would also be problematic to simply mark the hash (transfer full), since we need to either assume that the caller passed a destroy function when creating the hash (pygobject does not) or deallocate the values ourselves when the match rule is finalized (which requires making assumptions about the correct free function needed to deallocate the values that the caller allocated). So it seems that the only safe thing to do is to copy the hash.
-rw-r--r--atspi/atspi-matchrule.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/atspi/atspi-matchrule.c b/atspi/atspi-matchrule.c
index 80783d17..76415c28 100644
--- a/atspi/atspi-matchrule.c
+++ b/atspi/atspi-matchrule.c
@@ -60,6 +60,9 @@ atspi_match_rule_finalize (GObject *object)
if (rule->interfaces)
g_array_free (rule->interfaces, TRUE);
+ if (rule->attributes)
+ g_hash_table_unref (rule->attributes);
+
G_OBJECT_CLASS (atspi_match_rule_parent_class)->finalize (object);
}
@@ -119,8 +122,19 @@ atspi_match_rule_new (AtspiStateSet *states,
rule->statematchtype = statematchtype;
if (attributes)
- rule->attributes = g_hash_table_ref (attributes);
- rule->attributematchtype = attributematchtype;
+ {
+ GHashTableIter hash_table_iter;
+ gchar *key, *value;
+ rule->attributes = g_hash_table_new_full (g_str_hash, g_str_equal,
+ (GDestroyNotify) g_free,
+ (GDestroyNotify) g_free);
+ g_hash_table_iter_init (&hash_table_iter, attributes);
+ while (g_hash_table_iter_next (&hash_table_iter, (gpointer *)&key,
+ (gpointer *)&value))
+ g_hash_table_insert (rule->attributes, g_strdup (key), g_strdup (value));
+ } else
+ rule->attributes = NULL;
+ rule->attributematchtype = attributematchtype;
if (interfaces)
rule->interfaces = g_array_ref (interfaces);
@@ -147,7 +161,7 @@ atspi_match_rule_new (AtspiStateSet *states,
}
static void
-append_entry (gpointer *key, gpointer *val, gpointer data)
+append_entry (gpointer key, gpointer val, gpointer data)
{
DBusMessageIter *iter = data;
DBusMessageIter iter_entry;