layers: Fix thread-safety fails in OT FreeXxx APIs
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
diff --git a/layers/object_tracker.cpp b/layers/object_tracker.cpp
index 16140d6..7f49f56 100644
--- a/layers/object_tracker.cpp
+++ b/layers/object_tracker.cpp
@@ -3367,16 +3367,15 @@
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 @@
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;
}