summaryrefslogtreecommitdiff
path: root/atspi/atspi-matchrule.c
diff options
context:
space:
mode:
authorMike Gorse <mgorse@novell.com>2011-05-17 14:00:40 -0500
committerMike Gorse <mgorse@novell.com>2011-05-17 14:00:40 -0500
commit05237f4e33de73b6826807aef1bdfa7a0261821b (patch)
treebe168d40d9f3b6b0113fa45821f40548561ce8fa /atspi/atspi-matchrule.c
parent288a8d842fd8ef84ee5bfcc68ac1808dd6a49838 (diff)
downloadat-spi2-core-05237f4e33de73b6826807aef1bdfa7a0261821b.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.
Diffstat (limited to 'atspi/atspi-matchrule.c')
-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;