From c131865f57c2786d1a498d58b9b4c1333397798c Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Fri, 3 Feb 2017 10:03:56 +0000 Subject: [PATCH] gdbus: Fix atomic accesses to global name watch ID https://bugzilla.gnome.org/show_bug.cgi?id=777307 --- gio/gdbusnamewatching.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/gio/gdbusnamewatching.c b/gio/gdbusnamewatching.c index 01ab4ce24..14603c5e4 100644 --- a/gio/gdbusnamewatching.c +++ b/gio/gdbusnamewatching.c @@ -77,7 +77,10 @@ typedef struct gboolean initialized; } Client; -static guint next_global_id = 1; +/* Must be accessed atomically. */ +static volatile guint next_global_id = 1; + +/* Must be accessed with @lock held. */ static GHashTable *map_id_to_client = NULL; static Client * @@ -562,7 +565,7 @@ g_bus_watch_name (GBusType bus_type, client = g_new0 (Client, 1); client->ref_count = 1; - client->id = next_global_id++; /* TODO: uh oh, handle overflow */ + client->id = g_atomic_int_add (&next_global_id, 1); /* TODO: uh oh, handle overflow */ client->name = g_strdup (name); client->flags = flags; client->name_appeared_handler = name_appeared_handler; @@ -624,7 +627,7 @@ guint g_bus_watch_name_on_connection (GDBusConnection *connection, client = g_new0 (Client, 1); client->ref_count = 1; - client->id = next_global_id++; /* TODO: uh oh, handle overflow */ + client->id = g_atomic_int_add (&next_global_id, 1); /* TODO: uh oh, handle overflow */ client->name = g_strdup (name); client->flags = flags; client->name_appeared_handler = name_appeared_handler;