]> git.mdlowis.com Git - proto/labwc.git/commitdiff
xwayland: prevent crash due to unexpected surface dissociate events
authorJohn Lindgren <john@jlindgren.net>
Tue, 23 Jan 2024 23:22:56 +0000 (18:22 -0500)
committerJohan Malm <johanmalm@users.noreply.github.com>
Wed, 24 Jan 2024 18:55:21 +0000 (18:55 +0000)
Fixes #1360
Fixes #1466

src/xwayland-unmanaged.c
src/xwayland.c

index 3910eb2a0d95c72566c92156c51290109b1e3407..036b702b703aa725e35f56bac7e4c369091b18f0 100644 (file)
@@ -135,6 +135,19 @@ handle_dissociate(struct wl_listener *listener, void *data)
        struct xwayland_unmanaged *unmanaged =
                wl_container_of(listener, unmanaged, dissociate);
 
+       if (!unmanaged->mappable.connected) {
+               /*
+                * In some cases wlroots fails to emit the associate event
+                * due to an early return in xwayland_surface_associate().
+                * This is arguably a wlroots bug, but nevertheless it
+                * should not bring down labwc.
+                *
+                * TODO: Potentially remove when starting to track
+                *       wlroots 0.18 and it got fixed upstream.
+                */
+               wlr_log(WLR_ERROR, "dissociate received before associate");
+               return;
+       }
        mappable_disconnect(&unmanaged->mappable);
 }
 
@@ -225,6 +238,9 @@ xwayland_unmanaged_create(struct server *server,
        CONNECT_SIGNAL(xsurface, unmanaged, request_configure);
        CONNECT_SIGNAL(xsurface, unmanaged, set_override_redirect);
 
+       if (xsurface->surface) {
+               handle_associate(&unmanaged->associate, NULL);
+       }
        if (mapped) {
                handle_map(&unmanaged->mappable.map, NULL);
        }
index d032fd435f930b057caeb49a8de053fa0b91d7bf..60ce52749a467c28d3848d4c9079d04e770508af 100644 (file)
@@ -252,6 +252,19 @@ handle_dissociate(struct wl_listener *listener, void *data)
        struct xwayland_view *xwayland_view =
                wl_container_of(listener, xwayland_view, dissociate);
 
+       if (!xwayland_view->base.mappable.connected) {
+               /*
+                * In some cases wlroots fails to emit the associate event
+                * due to an early return in xwayland_surface_associate().
+                * This is arguably a wlroots bug, but nevertheless it
+                * should not bring down labwc.
+                *
+                * TODO: Potentially remove when starting to track
+                *       wlroots 0.18 and it got fixed upstream.
+                */
+               wlr_log(WLR_ERROR, "dissociate received before associate");
+               return;
+       }
        mappable_disconnect(&xwayland_view->base.mappable);
 }
 
@@ -855,6 +868,9 @@ xwayland_view_create(struct server *server,
 
        wl_list_insert(&view->server->views, &view->link);
 
+       if (xsurface->surface) {
+               handle_associate(&xwayland_view->associate, NULL);
+       }
        if (mapped) {
                xwayland_view_map(view);
        }