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 <liang.zhou@gehealthcare.com>
This commit is contained in:
liang zhou 2025-05-16 17:29:57 +08:00 committed by liang zhou
parent df8af39a2a
commit 4e4d7993ba

View file

@ -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,