[at-spi2-core] In atspi_match_rule_get_attributes, copy the hash rather than ref it
- From: Mike Gorse <mgorse src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [at-spi2-core] In atspi_match_rule_get_attributes, copy the hash rather than ref it
- Date: Tue, 17 May 2011 19:01:18 +0000 (UTC)
commit 05237f4e33de73b6826807aef1bdfa7a0261821b
Author: Mike Gorse <mgorse novell com>
Date: Tue May 17 14:00:40 2011 -0500
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.
atspi/atspi-matchrule.c | 20 +++++++++++++++++---
1 files changed, 17 insertions(+), 3 deletions(-)
---
diff --git a/atspi/atspi-matchrule.c b/atspi/atspi-matchrule.c
index 80783d1..76415c2 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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]