mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-01 15:03:39 +02:00
g_bus_own_name: fix race when unowning a name immediately after owning it
... and also add a test to verify that the fix works. https://bugzilla.gnome.org/show_bug.cgi?id=662808 Signed-off-by: David Zeuthen <davidz@redhat.com>
This commit is contained in:
@@ -213,6 +213,31 @@ test_bus_own_name (void)
|
||||
g_assert (!name_has_owner_reply);
|
||||
g_variant_unref (result);
|
||||
|
||||
/* Now try owning the name and then immediately decide to unown the name */
|
||||
g_assert_cmpint (data.num_bus_acquired, ==, 1);
|
||||
g_assert_cmpint (data.num_acquired, ==, 1);
|
||||
g_assert_cmpint (data.num_lost, ==, 0);
|
||||
g_assert_cmpint (data.num_free_func, ==, 2);
|
||||
id = g_bus_own_name (G_BUS_TYPE_SESSION,
|
||||
name,
|
||||
G_BUS_NAME_OWNER_FLAGS_NONE,
|
||||
bus_acquired_handler,
|
||||
name_acquired_handler,
|
||||
name_lost_handler,
|
||||
&data,
|
||||
(GDestroyNotify) own_name_data_free_func);
|
||||
g_assert_cmpint (data.num_bus_acquired, ==, 1);
|
||||
g_assert_cmpint (data.num_acquired, ==, 1);
|
||||
g_assert_cmpint (data.num_lost, ==, 0);
|
||||
g_assert_cmpint (data.num_free_func, ==, 2);
|
||||
g_bus_unown_name (id);
|
||||
g_assert_cmpint (data.num_bus_acquired, ==, 1);
|
||||
g_assert_cmpint (data.num_acquired, ==, 1);
|
||||
g_assert_cmpint (data.num_lost, ==, 0);
|
||||
g_assert_cmpint (data.num_free_func, ==, 2);
|
||||
g_main_loop_run (loop); /* the GDestroyNotify is called in idle because the bus is acquired in idle */
|
||||
g_assert_cmpint (data.num_free_func, ==, 3);
|
||||
|
||||
/*
|
||||
* Own the name again.
|
||||
*/
|
||||
@@ -344,7 +369,7 @@ test_bus_own_name (void)
|
||||
g_bus_unown_name (id);
|
||||
g_assert_cmpint (data.num_bus_acquired, ==, 1);
|
||||
g_assert_cmpint (data.num_acquired, ==, 1);
|
||||
g_assert_cmpint (data.num_free_func, ==, 3);
|
||||
g_assert_cmpint (data.num_free_func, ==, 4);
|
||||
/* grab it again */
|
||||
data.num_bus_acquired = 0;
|
||||
data.num_acquired = 0;
|
||||
@@ -443,7 +468,7 @@ test_bus_own_name (void)
|
||||
g_assert_cmpint (data.num_acquired, ==, 2);
|
||||
g_assert_cmpint (data.num_lost, ==, 2);
|
||||
g_bus_unown_name (id);
|
||||
g_assert_cmpint (data.num_free_func, ==, 4);
|
||||
g_assert_cmpint (data.num_free_func, ==, 5);
|
||||
|
||||
_g_object_wait_for_single_ref (c);
|
||||
g_object_unref (c);
|
||||
|
Reference in New Issue
Block a user