Skip to content

xmlInitGlobals() is not thread-safe

If xmlInitGlobals() is called from two different threads before xmlThrDefMutex is initialized, a race could occur where a pthread_mutex_t created by xmlNewMutex() was leaked, and (worse) one thread might use the wrong (leaked) mutex, thus causing thread safety issues.

The fix is to add proper locking to make sure xmlThrDefMutex is initialized exactly once.

  • globals.c: Add per-platform global static variable used to ensure _xmlInitGlobalsOnce() is only called once. (xmlInitGlobals): Add code from xmlOnceInit() in threads.c to ensure _xmlInitGlobalsOnce() is only called once. (_xmlInitGlobalsOnce): Extract from xmlInitGlobals(). It just initializes the xmlThrDefMutex global.

#2 (closed)

Merge request reports