windows: Fix invalid pointer dereference when terminating service thread

When running as a service, the libraries are initialized/deinitialized
not by the main thread but by a separate thread that runs the registered
main service procedure.  When the service is stopped, the libraries are
deinitialized by that thread and the thread lock and hashtable are
destroyed.  But afterwards the DllMain callback is also triggered for
that thread so we have to prevent it from accessing these objects again.

References strongswan/strongswan#1567
This commit is contained in:
Tobias Brunner
2023-03-21 16:27:10 +01:00
parent e6a354a996
commit 8f5c0c9ca9
@@ -637,6 +637,12 @@ static void cleanup_tls()
private_thread_t *this;
bool old;
/* ignore this if called for the thread that called threads_deinit() */
if (!threads_lock)
{
return;
}
old = set_leak_detective(FALSE);
threads_lock->lock(threads_lock);
@@ -698,5 +704,6 @@ void threads_deinit()
destroy(this);
threads_lock->destroy(threads_lock);
threads_lock = NULL;
threads->destroy(threads);
}