layers: Fix thread-safety fails in OT FreeXxx APIs
authorMark Lobodzinski <mark@lunarg.com>
Wed, 13 Jul 2016 17:29:00 +0000 (11:29 -0600)
committerMark Lobodzinski <mark@lunarg.com>
Fri, 22 Jul 2016 17:32:26 +0000 (11:32 -0600)
Tracking data was cleaned up after calling down the chain in
FreeCommandBuffers and FreeDescriptorSets -- this left a hole that
another thread could walk through and corrupt the tracking data.

Change-Id: I7cc9c9bfae9f1ea179122125dd09952650f14d81

layers/object_tracker.cpp

index 16140d6..7f49f56 100644 (file)
@@ -3367,16 +3367,15 @@ VKAPI_ATTR void VKAPI_CALL FreeCommandBuffers(VkDevice device, VkCommandPool com
         skip_call |= ValidateCommandBuffer(device, commandPool, pCommandBuffers[i]);
     }
 
+    for (uint32_t i = 0; i < commandBufferCount; i++) {
+        DestroyDispatchableObject(device, pCommandBuffers[i], VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT);
+    }
+
     lock.unlock();
     if (!skip_call) {
         get_dispatch_table(ot_device_table_map, device)
             ->FreeCommandBuffers(device, commandPool, commandBufferCount, pCommandBuffers);
     }
-
-    lock.lock();
-    for (uint32_t i = 0; i < commandBufferCount; i++) {
-        DestroyDispatchableObject(device, pCommandBuffers[i], VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT);
-    }
 }
 VKAPI_ATTR void VKAPI_CALL DestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain, const VkAllocationCallbacks *pAllocator) {
     layer_data *device_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
@@ -3411,16 +3410,15 @@ VKAPI_ATTR VkResult VKAPI_CALL FreeDescriptorSets(VkDevice device, VkDescriptorP
         skip_call |= ValidateDescriptorSet(device, descriptorPool, pDescriptorSets[i]);
     }
 
+    for (uint32_t i = 0; i < descriptorSetCount; i++) {
+        DestroyNonDispatchableObject(device, pDescriptorSets[i], VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT);
+    }
+
     lock.unlock();
     if (!skip_call) {
         result = get_dispatch_table(ot_device_table_map, device)
                      ->FreeDescriptorSets(device, descriptorPool, descriptorSetCount, pDescriptorSets);
     }
-
-    lock.lock();
-    for (uint32_t i = 0; i < descriptorSetCount; i++) {
-        DestroyNonDispatchableObject(device, pDescriptorSets[i], VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT);
-    }
     return result;
 }