radv: destroy the base object if VkCreateFence() failed
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Fri, 10 Jul 2020 15:29:21 +0000 (17:29 +0200)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Wed, 15 Jul 2020 11:53:32 +0000 (13:53 +0200)
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5868>

src/amd/vulkan/radv_device.c

index 89bb732d5f92b72f4fb624d1fe9577850abfef47..8f2ea1b0def4bf484b2d2a241ad69511f4a8fff3 100644 (file)
@@ -5160,6 +5160,24 @@ static bool radv_sparse_bind_has_effects(const VkBindSparseInfo *info)
        return VK_SUCCESS;
 }
 
+static void
+radv_destroy_fence(struct radv_device *device,
+                  const VkAllocationCallbacks *pAllocator,
+                  struct radv_fence *fence)
+{
+       if (fence->temp_syncobj)
+               device->ws->destroy_syncobj(device->ws, fence->temp_syncobj);
+       if (fence->syncobj)
+               device->ws->destroy_syncobj(device->ws, fence->syncobj);
+       if (fence->fence)
+               device->ws->destroy_fence(fence->fence);
+       if (fence->fence_wsi)
+               fence->fence_wsi->destroy(fence->fence_wsi);
+
+       vk_object_base_finish(&fence->base);
+       vk_free2(&device->vk.alloc, pAllocator, fence);
+}
+
 VkResult radv_CreateFence(
        VkDevice                                    _device,
        const VkFenceCreateInfo*                    pCreateInfo,
@@ -5186,7 +5204,7 @@ VkResult radv_CreateFence(
        if (device->always_use_syncobj || handleTypes) {
                int ret = device->ws->create_syncobj(device->ws, &fence->syncobj);
                if (ret) {
-                       vk_free2(&device->vk.alloc, pAllocator, fence);
+                       radv_destroy_fence(device, pAllocator, fence);
                        return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
                }
                if (pCreateInfo->flags & VK_FENCE_CREATE_SIGNALED_BIT) {
@@ -5196,7 +5214,7 @@ VkResult radv_CreateFence(
        } else {
                fence->fence = device->ws->create_fence();
                if (!fence->fence) {
-                       vk_free2(&device->vk.alloc, pAllocator, fence);
+                       radv_destroy_fence(device, pAllocator, fence);
                        return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
                }
                fence->syncobj = 0;
@@ -5220,17 +5238,7 @@ void radv_DestroyFence(
        if (!fence)
                return;
 
-       if (fence->temp_syncobj)
-               device->ws->destroy_syncobj(device->ws, fence->temp_syncobj);
-       if (fence->syncobj)
-               device->ws->destroy_syncobj(device->ws, fence->syncobj);
-       if (fence->fence)
-               device->ws->destroy_fence(fence->fence);
-       if (fence->fence_wsi)
-               fence->fence_wsi->destroy(fence->fence_wsi);
-
-       vk_object_base_finish(&fence->base);
-       vk_free2(&device->vk.alloc, pAllocator, fence);
+       radv_destroy_fence(device, pAllocator, fence);
 }