mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-10-23 01:52:48 +03:00
Fix potentially-uninitialized critical section in Win32 DLL builds
If non-parser parts of libxml (e.g. xmlwriter) are used before a parser, xmlOnceInit may have run (e.g. via the many paths to xmlGetGlobalState), but not xmlInitThreads (which is called only by xmlInitParser) Once globalkey != TLS_OUT_OF_INDEXES (which can happen in many ways), DLLMAIN(DLL_THREAD_DETACH) may attempt to lock cleanup_helpers_cs before it is valid. This may happen even if the thread whose exit is triggering DllMain is from code which is not linked to libxml. globalkey and cleanup_helpers_cs should be initialized together, with cleanup_helpers_cs initialized first and deleted last.
This commit is contained in:
committed by
Nick Wellnhofer
parent
c2e09f445c
commit
453bdfb95e
@@ -885,8 +885,6 @@ xmlInitThreads(void)
|
||||
}
|
||||
}
|
||||
#endif /* XML_PTHREAD_WEAK */
|
||||
#elif defined(HAVE_WIN32_THREADS) && !defined(HAVE_COMPILER_TLS) && (!defined(LIBXML_STATIC) || defined(LIBXML_STATIC_FOR_DLL))
|
||||
InitializeCriticalSection(&cleanup_helpers_cs);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -958,6 +956,9 @@ xmlOnceInit(void)
|
||||
if (!run_once.done) {
|
||||
if (InterlockedIncrement(&run_once.control) == 1) {
|
||||
#if !defined(HAVE_COMPILER_TLS)
|
||||
#if !defined(LIBXML_STATIC) || defined(LIBXML_STATIC_FOR_DLL)
|
||||
InitializeCriticalSection(&cleanup_helpers_cs);
|
||||
#endif
|
||||
globalkey = TlsAlloc();
|
||||
#endif
|
||||
mainthread = GetCurrentThreadId();
|
||||
|
Reference in New Issue
Block a user