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
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);
destroy(this);
threads_lock->destroy(threads_lock);
+ threads_lock = NULL;
threads->destroy(threads);
}