From 45375561bccd0a47ec94ed814d7805c840079f0e Mon Sep 17 00:00:00 2001 From: Keyu Tao Date: Wed, 15 Feb 2023 03:04:54 +0800 Subject: Fix idle monitor watch leak When an idle monitor watch is added and then removed by application, it is possible that watch->dead is marked when on_watch_added() is running. However, in this condition libgnome-desktop does not actually remove this watch in upstream (meta). This idle monitor watch leak may affect the performance of mutter when it has been running for a few days. --- libgnome-desktop/gnome-idle-monitor.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/libgnome-desktop/gnome-idle-monitor.c b/libgnome-desktop/gnome-idle-monitor.c index 677ddf5c..1cbad8e1 100644 --- a/libgnome-desktop/gnome-idle-monitor.c +++ b/libgnome-desktop/gnome-idle-monitor.c @@ -375,6 +375,7 @@ on_watch_added (GObject *object, GnomeIdleMonitor *monitor; GError *error; GVariant *res; + guint upstream_id; error = NULL; res = g_dbus_proxy_call_finish (G_DBUS_PROXY (object), result, &error); @@ -391,15 +392,22 @@ on_watch_added (GObject *object, return; } + g_variant_get (res, "(u)", &upstream_id); + g_variant_unref (res); + if (watch->dead) { + if (upstream_id) { + meta_dbus_idle_monitor_call_remove_watch (watch->monitor->priv->proxy, + upstream_id, + NULL, NULL, NULL); + } idle_monitor_watch_unref (watch); return; } monitor = watch->monitor; - g_variant_get (res, "(u)", &watch->upstream_id); - g_variant_unref (res); + watch->upstream_id = upstream_id; g_hash_table_insert (monitor->priv->watches_by_upstream_id, GINT_TO_POINTER (watch->upstream_id), watch); idle_monitor_watch_unref (watch); -- cgit v1.2.1