From 50497cea031a6b4eeba324d4f6962f6f0adc2ea3 Mon Sep 17 00:00:00 2001 From: George Kiagiadakis Date: Fri, 22 Mar 2024 15:35:22 +0200 Subject: [PATCH] m-std-event-source: cancel events when the node associated with the si dies It is possible that a node is destroyed while the select-target event is ongoing. In that case, the next hook to run will likely crash. Fix this by cancelling events automatically when their subject is a session-item associated with a node, as soon as the node is destroyed. See !619 --- modules/module-standard-event-source.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/modules/module-standard-event-source.c b/modules/module-standard-event-source.c index ac59b9f4..6ed2a4be 100644 --- a/modules/module-standard-event-source.c +++ b/modules/module-standard-event-source.c @@ -246,11 +246,23 @@ wp_standard_event_source_create_event (WpStandardEventSource *self, /* watch for subject pw-proxy-destroyed and cancel event, unless this is a "removed" event, in which case we expect the proxy to be destroyed and the event should still go through */ - if (subject && !g_str_has_suffix (event_type, "-removed") - && g_type_is_a (G_OBJECT_TYPE (subject), WP_TYPE_PROXY)) { - g_signal_connect_object (subject, "pw-proxy-destroyed", - (GCallback) g_cancellable_cancel, wp_event_get_cancellable (event), - G_CONNECT_SWAPPED); + if (subject && !g_str_has_suffix (event_type, "-removed")) { + g_autoptr (WpProxy) proxy = NULL; + + if (WP_IS_PROXY (subject)) { + proxy = g_object_ref (WP_PROXY (subject)); + } + else if (WP_IS_SESSION_ITEM (subject)) { + /* watch the node associated with the session-item */ + proxy = wp_session_item_get_associated_proxy (WP_SESSION_ITEM (subject), + WP_TYPE_NODE); + } + + if (proxy) { + g_signal_connect_object (proxy, "pw-proxy-destroyed", + (GCallback) g_cancellable_cancel, wp_event_get_cancellable (event), + G_CONNECT_SWAPPED); + } } return g_steal_pointer (&event);