radv: destroy the base object if VkCreateBuffer() failed
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Fri, 10 Jul 2020 15:11:10 +0000 (17:11 +0200)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Wed, 15 Jul 2020 11:53:27 +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 407cc6fc6ac63c78157c246287163a2a2a0c8f5f..f449199d9943834613a4aec762256afd1c98eb00 100644 (file)
@@ -5886,6 +5886,18 @@ VkResult radv_ResetEvent(
        return VK_SUCCESS;
 }
 
+static void
+radv_destroy_buffer(struct radv_device *device,
+                   const VkAllocationCallbacks *pAllocator,
+                   struct radv_buffer *buffer)
+{
+       if ((buffer->flags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT) && buffer->bo)
+               device->ws->buffer_destroy(buffer->bo);
+
+       vk_object_base_finish(&buffer->base);
+       vk_free2(&device->vk.alloc, pAllocator, buffer);
+}
+
 VkResult radv_CreateBuffer(
        VkDevice                                    _device,
        const VkBufferCreateInfo*                   pCreateInfo,
@@ -5922,7 +5934,7 @@ VkResult radv_CreateBuffer(
                                                       4096, 0, RADEON_FLAG_VIRTUAL,
                                                       RADV_BO_PRIORITY_VIRTUAL);
                if (!buffer->bo) {
-                       vk_free2(&device->vk.alloc, pAllocator, buffer);
+                       radv_destroy_buffer(device, pAllocator, buffer);
                        return vk_error(device->instance, VK_ERROR_OUT_OF_DEVICE_MEMORY);
                }
        }
@@ -5943,11 +5955,7 @@ void radv_DestroyBuffer(
        if (!buffer)
                return;
 
-       if (buffer->flags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT)
-               device->ws->buffer_destroy(buffer->bo);
-
-       vk_object_base_finish(&buffer->base);
-       vk_free2(&device->vk.alloc, pAllocator, buffer);
+       radv_destroy_buffer(device, pAllocator, buffer);
 }
 
 VkDeviceAddress radv_GetBufferDeviceAddress(