On Mon, Aug 02, 2010 at 04:42:33PM +0200, Mike Hommey <m...@glandium.org> wrote:
> On Mon, Aug 02, 2010 at 12:12:53PM +0200, Mike Hommey <m...@glandium.org> 
> wrote:
> > Upstream is partially responsible for the problem. I'd say there are 
> > actually
> > 2 different problems. The first one is that despite using weak symbols, the
> > initialization steps don't check if the symbols are resolved before using
> > them. That should IMHO be fixed in libxml2, instead of removing weak 
> > symbols.
> > The fix should be straightforward.
> 
> Reading the code more thoroughly, it does the check, but there may be code
> paths where the result of that test is not checked before calling pthread
> functions.

The attached patch works for me.

Mike
diff --git a/parser.c b/parser.c
index 85e7599..1db706b 100644
--- a/parser.c
+++ b/parser.c
@@ -14004,8 +14004,8 @@ xmlInitParser(void) {
     __xmlGlobalInitMutexLock();
     if (xmlParserInitialized == 0) {
 #endif
-	xmlInitGlobals();
 	xmlInitThreads();
+	xmlInitGlobals();
 	if ((xmlGenericError == xmlGenericErrorDefaultFunc) ||
 	    (xmlGenericError == NULL))
 	    initGenericErrorDefaultFunc(NULL);
diff --git a/threads.c b/threads.c
index 98fd2c2..1eeac0e 100644
--- a/threads.c
+++ b/threads.c
@@ -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);

Reply via email to