radv: Free syncobj with multiple imports.
authorBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Mon, 13 Nov 2017 22:18:19 +0000 (23:18 +0100)
committerBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Tue, 14 Nov 2017 09:03:02 +0000 (10:03 +0100)
Otherwise we can leak the old syncobj.

Fixes: eaa56eab6da "radv: initial support for shared semaphores (v2)"
Reviewed-by: Dave Airlie <airlied@redhat.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
src/amd/vulkan/radv_device.c

index 929082182c24290e09359e79218017b5e1a213b8..4e3ad111382cfbf03665f623f397ff68ee6992a1 100644 (file)
@@ -3525,6 +3525,7 @@ VkResult radv_ImportSemaphoreFdKHR(VkDevice _device,
        RADV_FROM_HANDLE(radv_device, device, _device);
        RADV_FROM_HANDLE(radv_semaphore, sem, pImportSemaphoreFdInfo->semaphore);
        uint32_t syncobj_handle = 0;
+       uint32_t *syncobj_dst = NULL;
        assert(pImportSemaphoreFdInfo->handleType == VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR);
 
        int ret = device->ws->import_syncobj(device->ws, pImportSemaphoreFdInfo->fd, &syncobj_handle);
@@ -3532,10 +3533,15 @@ VkResult radv_ImportSemaphoreFdKHR(VkDevice _device,
                return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR);
 
        if (pImportSemaphoreFdInfo->flags & VK_SEMAPHORE_IMPORT_TEMPORARY_BIT_KHR) {
-               sem->temp_syncobj = syncobj_handle;
+               syncobj_dst = &sem->temp_syncobj;
        } else {
-               sem->syncobj = syncobj_handle;
+               syncobj_dst = &sem->syncobj;
        }
+
+       if (*syncobj_dst)
+               device->ws->destroy_syncobj(device->ws, *syncobj_dst);
+
+       *syncobj_dst = syncobj_handle;
        close(pImportSemaphoreFdInfo->fd);
        return VK_SUCCESS;
 }