Commit e6f05099 authored by Mike Hommey's avatar Mike Hommey Committed by Daniel Veillard

Fix a potential segfault due to weak symbols on pthreads

In xmlInitParser, both __xmlGlobalInitMutexLock and xmlInitGlobals are
called before xmlInitThreads, and both use pthread symbols.
__xmlGlobalInitMutexLock does so directly, without checking if the symbol
exists, and xmlInitGlobals calls xmlNewMutex, which correctly depends on
libxml_is_threaded... except libxml_is_threaded is still -1 by then...
And again, when releasing the global mutex in __xmlGlobalInitMutexUnlock,
the pthread function is called directly.

The patch changes the initialization order and make sure the functions
are available before calling them
parent 3c79510d
......@@ -14004,8 +14004,8 @@ xmlInitParser(void) {
__xmlGlobalInitMutexLock();
if (xmlParserInitialized == 0) {
#endif
xmlInitGlobals();
xmlInitThreads();
xmlInitGlobals();
if ((xmlGenericError == xmlGenericErrorDefaultFunc) ||
(xmlGenericError == NULL))
initGenericErrorDefaultFunc(NULL);
......
......@@ -439,7 +439,8 @@ __xmlGlobalInitMutexLock(void)
/* Make sure the global init lock is initialized and then lock it. */
#ifdef HAVE_PTHREAD_H
/* The mutex is statically initialized, so we just lock it. */
pthread_mutex_lock(&global_init_lock);
if (pthread_mutex_lock)
pthread_mutex_lock(&global_init_lock);
#elif defined HAVE_WIN32_THREADS
LPCRITICAL_SECTION cs;
......@@ -508,7 +509,8 @@ void
__xmlGlobalInitMutexUnlock(void)
{
#ifdef HAVE_PTHREAD_H
pthread_mutex_unlock(&global_init_lock);
if (pthread_mutex_unlock)
pthread_mutex_unlock(&global_init_lock);
#elif defined HAVE_WIN32_THREADS
if (global_init_lock != NULL) {
LeaveCriticalSection(global_init_lock);
......
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