diff options
author | Andre Moreira Magalhaes <andre@endlessm.com> | 2019-07-23 20:33:19 +0000 |
---|---|---|
committer | Andre Moreira Magalhaes <andre@endlessm.com> | 2019-08-07 21:28:47 -0300 |
commit | a32e51142140e3886b50ba7348783d867e900d0b (patch) | |
tree | f3cab782b6871bb7c6e2086df40de68fb1984577 /gdbus/dconf-gdbus-common.c | |
parent | 6fbf07188542806f126bbee4f15bd0eb95057843 (diff) | |
download | dconf-a32e51142140e3886b50ba7348783d867e900d0b.tar.gz |
gdbus: Unref cached GDBusConnection objects when the connection is closed
This change fixes the dbus-leak tests by dropping the cached
GDBusConnection objects references when the bus connection is closed.
The issue was introduced with recent changes made to GLib[1]
where invoking g_test_dbus_down() will fail after a
timeout if the GDBusConnection object for the session bus leaks.
Given g_test_dbus_down() will first close the connection before checking
for leaks unreffing the object when the connection is closed should fix
the issue.
[1] https://gitlab.gnome.org/GNOME/glib/merge_requests/963
Signed-off-by: Andre Moreira Magalhaes <andre@endlessm.com>
Diffstat (limited to 'gdbus/dconf-gdbus-common.c')
-rw-r--r-- | gdbus/dconf-gdbus-common.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/gdbus/dconf-gdbus-common.c b/gdbus/dconf-gdbus-common.c new file mode 100644 index 0000000..4b1b00c --- /dev/null +++ b/gdbus/dconf-gdbus-common.c @@ -0,0 +1,42 @@ +#include "../engine/dconf-engine.h" + +void +dconf_engine_dbus_handle_connection_closed (GDBusConnection *connection, + gboolean remote_peer_vanished, + GError *error, + GMutex *bus_lock, + gboolean *bus_is_error, + gpointer *bus_data, + GCallback bus_closed_callback, + gpointer bus_closed_callback_user_data) +{ + g_return_if_fail (connection != NULL); + g_return_if_fail (bus_is_error != NULL); + g_return_if_fail (bus_data != NULL); + + g_debug ("D-Bus connection closed, invalidating cache: %s", + error != NULL ? error->message : + (remote_peer_vanished == FALSE ? "Close requested" : "Unknown reason")); + + g_mutex_lock (bus_lock); + + if (bus_closed_callback) + g_signal_handlers_disconnect_by_func (connection, + bus_closed_callback, + bus_closed_callback_user_data); + + if (*bus_is_error) + { + g_clear_error ((GError **) bus_data); + *bus_is_error = FALSE; + } + else + { + g_assert (connection == *bus_data); + *bus_data = NULL; + } + + g_object_unref (connection); + + g_mutex_unlock (bus_lock); +} |