Jelajahi Sumber

Fix potential memory leak in VULKAN_AcquireCommandBuffer() on error

Petar Popovic 3 hari lalu
induk
melakukan
77f4a8e2b8
1 mengubah file dengan 5 tambahan dan 4 penghapusan
  1. 5 4
      src/gpu/vulkan/SDL_gpu_vulkan.c

+ 5 - 4
src/gpu/vulkan/SDL_gpu_vulkan.c

@@ -9548,15 +9548,16 @@ static SDL_GPUCommandBuffer *VULKAN_AcquireCommandBuffer(
     VulkanCommandBuffer *commandBuffer =
     VulkanCommandBuffer *commandBuffer =
         VULKAN_INTERNAL_GetInactiveCommandBufferFromPool(renderer, threadID);
         VULKAN_INTERNAL_GetInactiveCommandBufferFromPool(renderer, threadID);
 
 
+    if (commandBuffer == NULL) {
+        SDL_UnlockMutex(renderer->acquireCommandBufferLock);
+        return NULL;
+    }
+
     DescriptorSetCache *descriptorSetCache =
     DescriptorSetCache *descriptorSetCache =
         VULKAN_INTERNAL_AcquireDescriptorSetCache(renderer);
         VULKAN_INTERNAL_AcquireDescriptorSetCache(renderer);
 
 
     SDL_UnlockMutex(renderer->acquireCommandBufferLock);
     SDL_UnlockMutex(renderer->acquireCommandBufferLock);
 
 
-    if (commandBuffer == NULL) {
-        return NULL;
-    }
-
     commandBuffer->descriptorSetCache = descriptorSetCache;
     commandBuffer->descriptorSetCache = descriptorSetCache;
 
 
     // Reset state
     // Reset state