From 5ba7755174abecc0a28ad38e6ef29fde186063bf Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 23 Jun 2011 13:39:00 +0100 Subject: [PATCH 8/8] DBusObjectTree: always access refcount atomically --- dbus/dbus-object-tree.c | 19 ++++++++++++++----- 1 files changed, 14 insertions(+), 5 deletions(-) diff --git a/dbus/dbus-object-tree.c b/dbus/dbus-object-tree.c index 28cfc8b..d244045 100644 --- a/dbus/dbus-object-tree.c +++ b/dbus/dbus-object-tree.c @@ -950,7 +950,7 @@ allocate_subtree_object (const char *name) len = strlen (name); - subtree = dbus_malloc (MAX (front_padding + (len + 1), sizeof (DBusObjectSubtree))); + subtree = dbus_malloc0 (MAX (front_padding + (len + 1), sizeof (DBusObjectSubtree))); if (subtree == NULL) return NULL; @@ -987,7 +987,7 @@ _dbus_object_subtree_new (const char *name, } subtree->user_data = user_data; - subtree->refcount.value = 1; + _dbus_atomic_inc (&subtree->refcount); subtree->subtrees = NULL; subtree->n_subtrees = 0; subtree->max_subtrees = 0; @@ -1002,8 +1002,14 @@ _dbus_object_subtree_new (const char *name, static DBusObjectSubtree * _dbus_object_subtree_ref (DBusObjectSubtree *subtree) { - _dbus_assert (subtree->refcount.value > 0); +#ifdef DBUS_DISABLE_ASSERT _dbus_atomic_inc (&subtree->refcount); +#else + dbus_int32_t old_value; + + old_value = _dbus_atomic_inc (&subtree->refcount); + _dbus_assert (old_value > 0); +#endif return subtree; } @@ -1011,9 +1017,12 @@ _dbus_object_subtree_ref (DBusObjectSubtree *subtree) static void _dbus_object_subtree_unref (DBusObjectSubtree *subtree) { - _dbus_assert (subtree->refcount.value > 0); + dbus_int32_t old_value; + + old_value = _dbus_atomic_dec (&subtree->refcount); + _dbus_assert (old_value > 0); - if (_dbus_atomic_dec (&subtree->refcount) == 1) + if (old_value == 1) { _dbus_assert (subtree->unregister_function == NULL); _dbus_assert (subtree->message_function == NULL); -- 1.7.5.4