Commit 9ac15d05 by Geoff Lang Committed by Commit Bot

Ensure the global mutex is not locked before deleting it.

It is undefined behaviour to delete a mutex that is locked by a thread. To ensure that the global mutex is not locked, lock/unlock it before deleting it. BUG=angleproject:2464 Change-Id: I735e924abfa06070f2b4103230be8593649ca340 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1690674 Commit-Queue: Geoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent b344fbd9
...@@ -147,14 +147,18 @@ bool DeallocateCurrentThread() ...@@ -147,14 +147,18 @@ bool DeallocateCurrentThread()
return SetTLSValue(threadTLS, nullptr); return SetTLSValue(threadTLS, nullptr);
} }
void DealocateDebug() void DeallocateDebug()
{ {
SafeDelete(g_Debug); SafeDelete(g_Debug);
} }
void DealocateMutex() void DeallocateMutex()
{ {
std::mutex *mutex = g_Mutex.exchange(nullptr); std::mutex *mutex = g_Mutex.exchange(nullptr);
{
// Wait for the mutex to become released by other threads before deleting.
std::lock_guard<std::mutex> lock(*mutex);
}
SafeDelete(mutex); SafeDelete(mutex);
} }
...@@ -176,9 +180,9 @@ bool InitializeProcess() ...@@ -176,9 +180,9 @@ bool InitializeProcess()
bool TerminateProcess() bool TerminateProcess()
{ {
DealocateDebug(); DeallocateDebug();
DealocateMutex(); DeallocateMutex();
if (!DeallocateCurrentThread()) if (!DeallocateCurrentThread())
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment