GitLab will be down for maintenance this Sunday 13th June, from approx 7-11am UTC. This is for a PostgreSQL migration. See the tracker issue for more informations.

Commit c62b8861 authored by Simon McVittie's avatar Simon McVittie
Browse files

DBusObjectTree: always access refcount atomically


Reviewed-by: default avatarCosimo Alfarano <cosimo.alfarano@collabora.co.uk>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=38005
parent d70ba600
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment