summaryrefslogtreecommitdiffstats
path: root/src/vulkan
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2017-11-15 19:59:01 -0800
committerJason Ekstrand <[email protected]>2017-12-04 10:04:19 -0800
commit3991098f3b10519b4308763fb77cd15e3218a044 (patch)
treec2a5c32145ca8cc11d176be7d707e7c8aef948ef /src/vulkan
parentc1163f7b1c3f56bb268f61205a67f019806ae785 (diff)
vulkan/wsi/x11: Handle the geometry check earlier in create_swapchain
This fixes a potential leak if allocating the swapchain fails. Since geometry checking and bit-depth fetching is self-contained, it makes sense to just do it first so we can delete the geometry reply. Reviewed-by: Dave Airlie <[email protected]> Reviewed-by: Chad Versace <[email protected]>
Diffstat (limited to 'src/vulkan')
-rw-r--r--src/vulkan/wsi/wsi_common_x11.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/vulkan/wsi/wsi_common_x11.c b/src/vulkan/wsi/wsi_common_x11.c
index 22b894edf00..51c103e967d 100644
--- a/src/vulkan/wsi/wsi_common_x11.c
+++ b/src/vulkan/wsi/wsi_common_x11.c
@@ -1107,19 +1107,21 @@ x11_surface_create_swapchain(VkIcdSurfaceBase *icd_surface,
const unsigned num_images = pCreateInfo->minImageCount;
- size_t size = sizeof(*chain) + num_images * sizeof(chain->images[0]);
- chain = vk_alloc(pAllocator, size, 8,
- VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
- if (chain == NULL)
- return VK_ERROR_OUT_OF_HOST_MEMORY;
-
+ /* Check for whether or not we have a window up-front */
xcb_connection_t *conn = x11_surface_get_connection(icd_surface);
xcb_window_t window = x11_surface_get_window(icd_surface);
xcb_get_geometry_reply_t *geometry =
xcb_get_geometry_reply(conn, xcb_get_geometry(conn, window), NULL);
-
if (geometry == NULL)
return VK_ERROR_SURFACE_LOST_KHR;
+ const uint32_t bit_depth = geometry->depth;
+ free(geometry);
+
+ size_t size = sizeof(*chain) + num_images * sizeof(chain->images[0]);
+ chain = vk_alloc(pAllocator, size, 8,
+ VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+ if (chain == NULL)
+ return VK_ERROR_OUT_OF_HOST_MEMORY;
chain->base.device = device;
chain->base.destroy = x11_swapchain_destroy;
@@ -1132,14 +1134,13 @@ x11_surface_create_swapchain(VkIcdSurfaceBase *icd_surface,
chain->base.image_count = num_images;
chain->conn = conn;
chain->window = window;
- chain->depth = geometry->depth;
+ chain->depth = bit_depth;
chain->extent = pCreateInfo->imageExtent;
chain->send_sbc = 0;
chain->last_present_msc = 0;
chain->threaded = false;
chain->status = VK_SUCCESS;
- free(geometry);
chain->base.needs_linear_copy = false;
if (!wsi_x11_check_dri3_compatible(conn, local_fd))