From baa8f6b1af47f8fc6e0d7029f102e8dbac4178c7 Mon Sep 17 00:00:00 2001 From: Daniel Stone Date: Tue, 18 May 2021 17:15:58 +0100 Subject: [PATCH] xdg-shell: Move check for surface having buffer earlier It's illegal to create an xdg_surface for a surface which already has a buffer attached to it. We check for this, but only after we've created our weston_desktop_surface; this simply avoids creating the internal tracking structure when we're only going to destroy it after posting the error. Signed-off-by: Daniel Stone --- libweston-desktop/xdg-shell.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libweston-desktop/xdg-shell.c b/libweston-desktop/xdg-shell.c index 4a9eb977..00f8f015 100644 --- a/libweston-desktop/xdg-shell.c +++ b/libweston-desktop/xdg-shell.c @@ -1422,6 +1422,13 @@ weston_desktop_xdg_shell_protocol_get_xdg_surface(struct wl_client *wl_client, wl_resource_get_user_data(surface_resource); struct weston_desktop_xdg_surface *surface; + if (wsurface->buffer_ref.buffer != NULL) { + wl_resource_post_error(resource, + XDG_SURFACE_ERROR_UNCONFIGURED_BUFFER, + "xdg_surface must not have a buffer at creation"); + return; + } + surface = zalloc(weston_desktop_surface_role_biggest_size); if (surface == NULL) { wl_client_post_no_memory(wl_client); @@ -1449,13 +1456,6 @@ weston_desktop_xdg_shell_protocol_get_xdg_surface(struct wl_client *wl_client, id, weston_desktop_xdg_surface_resource_destroy); if (surface->resource == NULL) return; - - if (wsurface->buffer_ref.buffer != NULL) { - wl_resource_post_error(surface->resource, - XDG_SURFACE_ERROR_UNCONFIGURED_BUFFER, - "xdg_surface must not have a buffer at creation"); - return; - } } static void