From: Tobias Brunner Date: Tue, 7 Mar 2023 15:57:27 +0000 (+0100) Subject: windows: Fix invalid pointer dereference when terminating service thread X-Git-Tag: 5.9.11dr1~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8f5c0c9ca926b9f936ada13f72f4b73756ecbc62;p=thirdparty%2Fstrongswan.git 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 --- diff --git a/src/libstrongswan/threading/windows/thread.c b/src/libstrongswan/threading/windows/thread.c index e70e4497b0..cb1b0c54d8 100644 --- a/src/libstrongswan/threading/windows/thread.c +++ b/src/libstrongswan/threading/windows/thread.c @@ -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); }