radv: Fix memory leak on error path.
authorVinson Lee <vlee@freedesktop.org>
Mon, 20 Dec 2021 03:10:21 +0000 (19:10 -0800)
committerVinson Lee <vlee@freedesktop.org>
Fri, 24 Dec 2021 08:15:53 +0000 (00:15 -0800)
Fix defects reported by Coverity Scan.

Resource leak (RESOURCE_LEAK)
leaked_storage: Variable signal_semaphore_infos going out of scope leaks the storage it points to
leaked_storage: Variable wait_semaphore_infos going out of scope leaks the storage it points to.

Fixes: 3da7d10d9bb ("radv: implement vkQueueSubmit2KHR()")
Signed-off-by: Vinson Lee <vlee@freedesktop.org>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14260>

src/amd/vulkan/radv_device.c

index d5fb9ad..be5004b 100644 (file)
@@ -5747,8 +5747,11 @@ radv_QueueBindSparse(VkQueue _queue, uint32_t bindInfoCount, const VkBindSparseI
       VkSemaphoreSubmitInfoKHR *signal_semaphore_infos =
          malloc(sizeof(*signal_semaphore_infos) * pBindInfo[i].signalSemaphoreCount);
 
-      if (!wait_semaphore_infos || !signal_semaphore_infos)
+      if (!wait_semaphore_infos || !signal_semaphore_infos) {
+         free(wait_semaphore_infos);
+         free(signal_semaphore_infos);
          return VK_ERROR_OUT_OF_HOST_MEMORY;
+      }
 
       for (uint32_t j = 0; j < pBindInfo[i].waitSemaphoreCount; j++) {
          wait_semaphore_infos[j] = (VkSemaphoreSubmitInfoKHR) {