loader: Destroy debug callbacks/messengers properly
When creating debug callbacks or messengers, each of them is added to a
linked list from the terminator, with the handle provided by the ICD.
When enabling some validation layers, this handle is renamed as part of
the chain and the application gets a different one.
In the removal process, the application usually receives one of these
function pointers using vkGetInstanceProcAddr:
- debug_utils_DestroyDebugReportCallbackEXT
- debug_utils_DestroyDebugUtilsMessengerEXT
Those trigger the chain calls but then try to remove the callback or
messenger from the linked list using the application-level handle, which
is not found because it doesn't match the one from the ICD.
The linked list should be accessed from the destruction terminators,
when the handle has already been unwrapped by the layers.
diff --git a/loader/debug_utils.c b/loader/debug_utils.c
index e41e146..10701e7 100644
--- a/loader/debug_utils.c
+++ b/loader/debug_utils.c
@@ -271,8 +271,6 @@
inst->disp->layer_inst_disp.DestroyDebugUtilsMessengerEXT(instance, messenger, pAllocator);
- util_DestroyDebugUtilsMessenger(inst, messenger, pAllocator);
-
loader_platform_thread_unlock_mutex(&loader_lock);
}
@@ -413,6 +411,8 @@
storage_idx++;
}
+ util_DestroyDebugUtilsMessenger(inst, messenger, pAllocator);
+
#if (DEBUG_DISABLE_APP_ALLOCATORS == 1)
{
#else
@@ -670,8 +670,6 @@
inst->disp->layer_inst_disp.DestroyDebugReportCallbackEXT(instance, callback, pAllocator);
- util_DestroyDebugReportCallback(inst, callback, pAllocator);
-
loader_platform_thread_unlock_mutex(&loader_lock);
}
@@ -821,6 +819,8 @@
storage_idx++;
}
+ util_DestroyDebugReportCallback(inst, callback, pAllocator);
+
#if (DEBUG_DISABLE_APP_ALLOCATORS == 1)
{
#else