vulkan/wsi: fix crash in failed swapchain creation for wayland
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Mon, 27 Feb 2023 17:41:11 +0000 (12:41 -0500)
committerMarge Bot <emma+marge@anholt.net>
Wed, 8 Mar 2023 17:33:00 +0000 (17:33 +0000)
this otherwise calls wsi_wl_swapchain_chain_free() before the wsi
pointer has been set

ref #6578

cc: mesa-stable

Acked-by: Daniel Stone <daniels@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21563>

src/vulkan/wsi/wsi_common_wayland.c

index 3f95c03..154d127 100644 (file)
@@ -1495,6 +1495,11 @@ static VkResult wsi_wl_surface_init(struct wsi_wl_surface *wsi_wl_surface,
    return VK_SUCCESS;
 
 fail:
+   if (wsi_wl_surface->surface)
+      wl_proxy_wrapper_destroy(wsi_wl_surface->surface);
+
+   if (wsi_wl_surface->display)
+      wsi_wl_display_destroy(wsi_wl_surface->display);
    return result;
 }
 
@@ -1958,10 +1963,8 @@ wsi_wl_surface_create_swapchain(VkIcdSurfaceBase *icd_surface,
 
    result = wsi_swapchain_init(wsi_device, &chain->base, device,
                                pCreateInfo, image_params, pAllocator);
-   if (result != VK_SUCCESS) {
-      vk_free(pAllocator, chain);
-      return result;
-   }
+   if (result != VK_SUCCESS)
+      goto fail;
 
    bool alpha = pCreateInfo->compositeAlpha ==
                       VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR;
@@ -2001,8 +2004,10 @@ wsi_wl_surface_create_swapchain(VkIcdSurfaceBase *icd_surface,
 fail_image_init:
    wsi_wl_swapchain_images_free(chain);
 
-fail:
    wsi_wl_swapchain_chain_free(chain, pAllocator);
+fail:
+   vk_free(pAllocator, chain);
+   wsi_wl_surface->chain = NULL;
 
    return result;
 }