From 137c793f226090ce79414bbb72581007223682cc Mon Sep 17 00:00:00 2001 From: Marius Vlad Date: Sat, 20 Nov 2021 19:14:45 +0200 Subject: [PATCH] desktop-shell: Guard against invalid seats in get_shell_seat() Starting with commit 'desktop-shell: Embed keyboard focus handle code when activating' we are iterating over all the seats when removing a weston_desktop_surface to be able to invalidate the activate surface. Upon compositor tear down the shell destroy might invalidate seats before removal of the weston_desktop_surface making the shell_seat itself invalid. This wasn't apparent at that time because we're not handling at that the removal of surfaces from layers. Signed-off-by: Marius Vlad --- desktop-shell/shell.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c index 7f84b6f3..19ccc412 100644 --- a/desktop-shell/shell.c +++ b/desktop-shell/shell.c @@ -2203,8 +2203,12 @@ get_shell_seat(struct weston_seat *seat) { struct wl_listener *listener; + if (!seat) + return NULL; + listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat); - assert(listener != NULL); + if (!listener) + return NULL; return container_of(listener, struct shell_seat, seat_destroy_listener); @@ -2340,7 +2344,7 @@ desktop_surface_removed(struct weston_desktop_surface *desktop_surface, * removed) surface when attempting to de-activate it. It will * also update the focused_surface once it has a chance to run. */ - if (surface == shseat->focused_surface) + if (shseat && surface == shseat->focused_surface) shseat->focused_surface = NULL; } @@ -3760,14 +3764,15 @@ activate(struct desktop_shell *shell, struct weston_view *view, weston_view_activate_input(view, seat, flags); - if (shseat->focused_surface) { + if (shseat && shseat->focused_surface) { struct shell_surface *current_focus = get_shell_surface(shseat->focused_surface); assert(current_focus); shell_surface_deactivate(current_focus); } - shseat->focused_surface = main_surface; + if (shseat) + shseat->focused_surface = main_surface; shell_surface_activate(shsurf); state = ensure_focus_state(shell, seat);