layers: Fix remaining leak in vkDestroyFramebuffers
authorChris Forbes <chrisforbes@google.com>
Thu, 31 Mar 2016 03:13:36 +0000 (16:13 +1300)
committerTobin Ehlis <tobine@google.com>
Thu, 31 Mar 2016 19:03:26 +0000 (13:03 -0600)
Also simplify & fix the thread safety of this function.
DestroyFramebuffers should not be in anybody's hot path -- and we
absolutely /must/ hold the mutex to touch these maps, so throw away all
the weird unlocking & relocking; just do it the simple way.

Signed-off-by: Chris Forbes <chrisforbes@google.com>
layers/core_validation.cpp

index d9a4144..7b97451 100644 (file)
@@ -6315,6 +6315,7 @@ VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetFences(VkDevice device, ui
 VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL
 vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer, const VkAllocationCallbacks *pAllocator) {
     layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
+    loader_platform_thread_lock_mutex(&globalLock);
     auto fbNode = dev_data->frameBufferMap.find(framebuffer);
     if (fbNode != dev_data->frameBufferMap.end()) {
         for (auto cb : fbNode->second.referencingCmdBuffers) {
@@ -6322,15 +6323,13 @@ vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer, const VkAllocat
             if (cbNode != dev_data->commandBufferMap.end()) {
                 // Set CB as invalid and record destroyed framebuffer
                 cbNode->second->state = CB_INVALID;
-                loader_platform_thread_lock_mutex(&globalLock);
                 cbNode->second->destroyedFramebuffers.insert(framebuffer);
-                loader_platform_thread_unlock_mutex(&globalLock);
             }
         }
-        loader_platform_thread_lock_mutex(&globalLock);
-        dev_data->frameBufferMap.erase(framebuffer);
-        loader_platform_thread_unlock_mutex(&globalLock);
+        delete [] fbNode->second.createInfo.pAttachments;
+        dev_data->frameBufferMap.erase(fbNode);
     }
+    loader_platform_thread_unlock_mutex(&globalLock);
     dev_data->device_dispatch_table->DestroyFramebuffer(device, framebuffer, pAllocator);
 }