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
This commit is contained in:
George Kiagiadakis
2024-03-22 15:35:22 +02:00
parent 428462ddf3
commit 50497cea03

View File

@@ -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);