[gnome-settings-daemon/wip/benzea/cleanups-and-small-fixes: 2/18] media-keys: Do not create weak references to GCancellable's
- From: Benjamin Berg <bberg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-settings-daemon/wip/benzea/cleanups-and-small-fixes: 2/18] media-keys: Do not create weak references to GCancellable's
- Date: Wed, 20 Feb 2019 16:11:31 +0000 (UTC)
commit 45d179565053913949b8ff7a811c221adaceb19d
Author: Benjamin Berg <bberg redhat com>
Date: Fri Feb 8 17:09:10 2019 +0100
media-keys: Do not create weak references to GCancellable's
The ensure_cancellable function was only ever called once. Also, the
cancellable may survive longer than the object so adding a weak
reference without removing it again potentially causes a use-after-free
situation.
Simply replacing it with g_cancellable_new makes things safe and also
simpler.
plugins/media-keys/gsd-media-keys-manager.c | 18 +++---------------
1 file changed, 3 insertions(+), 15 deletions(-)
---
diff --git a/plugins/media-keys/gsd-media-keys-manager.c b/plugins/media-keys/gsd-media-keys-manager.c
index f8c87762..209b704c 100644
--- a/plugins/media-keys/gsd-media-keys-manager.c
+++ b/plugins/media-keys/gsd-media-keys-manager.c
@@ -361,18 +361,6 @@ get_binding (GsdMediaKeysManager *manager,
g_assert_not_reached ();
}
-static void
-ensure_cancellable (GCancellable **cancellable)
-{
- if (*cancellable == NULL) {
- *cancellable = g_cancellable_new ();
- g_object_add_weak_pointer (G_OBJECT (*cancellable),
- (gpointer *)cancellable);
- } else {
- g_object_ref (*cancellable);
- }
-}
-
static void
show_osd_with_max_level (GsdMediaKeysManager *manager,
const char *icon,
@@ -2982,9 +2970,9 @@ start_media_keys_idle_cb (GsdMediaKeysManager *manager)
}
manager->priv->icon_theme = g_settings_get_string (manager->priv->interface_settings, "icon-theme");
- ensure_cancellable (&manager->priv->grab_cancellable);
- ensure_cancellable (&manager->priv->screencast_cancellable);
- ensure_cancellable (&manager->priv->rfkill_cancellable);
+ manager->priv->grab_cancellable = g_cancellable_new ();
+ manager->priv->screencast_cancellable = g_cancellable_new ();
+ manager->priv->rfkill_cancellable = g_cancellable_new ();
manager->priv->shell_proxy = gnome_settings_bus_get_shell_proxy ();
g_signal_connect_swapped (manager->priv->shell_proxy, "notify::g-name-owner",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]