vulkan/wsi/wayland: Fix double free on error condition

If wsi_configure_native_image() fails, it will call
wsi_destroy_image_info() itself, so let's try to not call it again from
wsi_wl_swapchain_destroy().

Fixes the CTS tests:
dEQP-VK.wsi.wayland.swapchain.simulate_oom.*

Fixes: b626a5be43 ("vulkan/wsi/wayland: Split image creation")

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16257>
(cherry picked from commit bf04be17f7)
This commit is contained in:
Iván Briano 2022-04-29 14:54:46 -07:00 committed by Dylan Baker
parent 78142c52f2
commit 9f062ad755
2 changed files with 23 additions and 8 deletions

View file

@ -380,7 +380,7 @@
"description": "vulkan/wsi/wayland: Fix double free on error condition",
"nominated": true,
"nomination_type": 1,
"resolution": 0,
"resolution": 1,
"because_sha": "b626a5be43d4cd81d6f6e7c17eef8f9055f555d7"
},
{

View file

@ -1217,12 +1217,9 @@ fail_image:
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
static VkResult
wsi_wl_swapchain_destroy(struct wsi_swapchain *wsi_chain,
const VkAllocationCallbacks *pAllocator)
static void
wsi_wl_swapchain_images_free(struct wsi_wl_swapchain *chain)
{
struct wsi_wl_swapchain *chain = (struct wsi_wl_swapchain *)wsi_chain;
for (uint32_t i = 0; i < chain->base.image_count; i++) {
if (chain->images[i].buffer) {
wl_buffer_destroy(chain->images[i].buffer);
@ -1232,7 +1229,12 @@ wsi_wl_swapchain_destroy(struct wsi_swapchain *wsi_chain,
}
}
wsi_destroy_image_info(&chain->base, &chain->base.image_info);
}
static void
wsi_wl_swapchain_chain_free(struct wsi_wl_swapchain *chain,
const VkAllocationCallbacks *pAllocator)
{
if (chain->frame)
wl_callback_destroy(chain->frame);
if (chain->surface)
@ -1244,6 +1246,16 @@ wsi_wl_swapchain_destroy(struct wsi_swapchain *wsi_chain,
wsi_swapchain_finish(&chain->base);
vk_free(pAllocator, chain);
}
static VkResult
wsi_wl_swapchain_destroy(struct wsi_swapchain *wsi_chain,
const VkAllocationCallbacks *pAllocator)
{
struct wsi_wl_swapchain *chain = (struct wsi_wl_swapchain *)wsi_chain;
wsi_wl_swapchain_images_free(chain);
wsi_wl_swapchain_chain_free(chain, pAllocator);
return VK_SUCCESS;
}
@ -1345,7 +1357,7 @@ wsi_wl_surface_create_swapchain(VkIcdSurfaceBase *icd_surface,
result = wsi_wl_image_init(chain, &chain->images[i],
pCreateInfo, pAllocator);
if (result != VK_SUCCESS)
goto fail;
goto fail_image_init;
chain->images[i].busy = false;
}
@ -1353,8 +1365,11 @@ wsi_wl_surface_create_swapchain(VkIcdSurfaceBase *icd_surface,
return VK_SUCCESS;
fail_image_init:
wsi_wl_swapchain_images_free(chain);
fail:
wsi_wl_swapchain_destroy(&chain->base, pAllocator);
wsi_wl_swapchain_chain_free(chain, pAllocator);
return result;
}