From f8a367896a57d84967d7b537ee618aae8081e2ea Mon Sep 17 00:00:00 2001 From: Marinus Klasen Date: Wed, 19 Aug 2026 23:05:34 +0200 Subject: wayland: clear touch focus in wayl_win_destroy() wl_touch has no leave event, so unmapping the surfaces cannot drop touch focus the way it drops keyboard and pointer focus. seat->touch.surface kept pointing at the window being destroyed, and seat->touch.state stayed HELD/DRAGGING, so the guard in wl_touch_up() and wl_touch_motion() did not fire. A wl_touch.up dispatched from the roundtrips in wayl_win_destroy() then dereferenced the freed window: #0 wl_touch_up () at input.c:3587 #12 wayl_roundtrip () at wayland.c:2416 #13 wayl_win_destroy () at wayland.c:2297 Reproduced by touching a foot window and holding while the window is destroyed: 3/3 crashes before, 0/7 after. --- wayland.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'wayland.c') diff --git a/wayland.c b/wayland.c index 7d81b486..f15c1687 100644 --- a/wayland.c +++ b/wayland.c @@ -2234,6 +2234,23 @@ wayl_win_destroy(struct wl_window *win) if (win->csd.move_timeout_fd != -1) close(win->csd.move_timeout_fd); + /* + * wl_touch has no leave event, so the unmapping below cannot drop touch + * focus the way it drops keyboard and pointer focus. Reset it here, or a + * wl_touch.up/motion dispatched from the roundtrips below runs against + * this window after it has been destroyed. + */ + tll_foreach(term->wl->seats, it) { + struct seat *seat = &it->item; + + if (seat->touch.surface != NULL && + wl_surface_get_user_data(seat->touch.surface) == win) + { + seat->touch.state = TOUCH_STATE_IDLE; + seat->touch.surface = NULL; + } + } + /* * First, unmap all surfaces to trigger things like * keyboard_leave() and wl_pointer_leave(). -- cgit v1.3