From 4e4d7993baff805c9c3a4c56d26026fbcc2c85d6 Mon Sep 17 00:00:00 2001 From: liang zhou Date: Fri, 16 May 2025 17:29:57 +0800 Subject: [PATCH] xdg-shell: fix weston crash while send configuration When xdg_toplevel_send_configure is executed, the xdg_toplevel resource may have already been destroyed, causing Weston to crash. Signed-off-by: liang zhou --- libweston/desktop/xdg-shell.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/libweston/desktop/xdg-shell.c b/libweston/desktop/xdg-shell.c index 2ee58b9b3..1f9fb3a73 100644 --- a/libweston/desktop/xdg-shell.c +++ b/libweston/desktop/xdg-shell.c @@ -1118,12 +1118,34 @@ static const struct xdg_popup_interface weston_desktop_xdg_popup_implementation .reposition = weston_desktop_xdg_popup_protocol_reposition, }; +static bool +weston_destop_xdg_surface_resource_available(struct weston_desktop_xdg_surface *surface) +{ + bool resource_available = false; + + switch (surface->role) { + case WESTON_DESKTOP_XDG_SURFACE_ROLE_NONE: + break; + case WESTON_DESKTOP_XDG_SURFACE_ROLE_TOPLEVEL: + resource_available = !!((struct weston_desktop_xdg_toplevel *) surface)->resource; + break; + case WESTON_DESKTOP_XDG_SURFACE_ROLE_POPUP: + resource_available = !!((struct weston_desktop_xdg_popup *) surface)->resource; + break; + } + + return resource_available; +} + static void weston_desktop_xdg_surface_send_configure(void *user_data) { struct weston_desktop_xdg_surface *surface = user_data; struct weston_desktop_xdg_surface_configure *configure; + if (!weston_destop_xdg_surface_resource_available(surface)) + return; + surface->configure_idle = NULL; configure = zalloc(weston_desktop_surface_configure_biggest_size); @@ -1504,6 +1526,9 @@ weston_desktop_xdg_surface_committed(struct weston_desktop_surface *dsurface, struct weston_surface *wsurface = weston_desktop_surface_get_surface (dsurface); + if (!weston_destop_xdg_surface_resource_available(surface)) + return; + if (weston_surface_has_content(wsurface) && !surface->configured) { wl_resource_post_error(surface->resource, XDG_SURFACE_ERROR_UNCONFIGURED_BUFFER,