[libxml2/2.9] Reset last error in xmlCleanupGlobals



commit 34e9d6aa7975396706230e5ce207299da1ab2733
Author: Nick Wellnhofer <wellnhofer aevum de>
Date:   Tue Mar 1 15:14:00 2022 +0100

    Reset last error in xmlCleanupGlobals
    
    Before, we tried to reset the last error in xmlCleanupParser. But if
    xmlCleanupParser wasn't called from the main thread, this would reset
    the thread-local error object. xmlCleanupGlobals has access to the
    error object of the main thread and can reset it reliably.

 globals.c | 30 ++++++++++++++++--------------
 parser.c  |  1 -
 2 files changed, 16 insertions(+), 15 deletions(-)
---
diff --git a/globals.c b/globals.c
index 0c0bdb44..893fb73a 100644
--- a/globals.c
+++ b/globals.c
@@ -50,20 +50,6 @@ void xmlInitGlobals(void)
         xmlThrDefMutex = xmlNewMutex();
 }
 
-/**
- * xmlCleanupGlobals:
- *
- * Additional cleanup for multi-threading
- */
-void xmlCleanupGlobals(void)
-{
-    if (xmlThrDefMutex != NULL) {
-       xmlFreeMutex(xmlThrDefMutex);
-       xmlThrDefMutex = NULL;
-    }
-    __xmlGlobalInitMutexDestroy();
-}
-
 /************************************************************************
  *                                                                     *
  *     All the user accessible global variables of the library         *
@@ -577,6 +563,22 @@ xmlInitializeGlobalState(xmlGlobalStatePtr gs)
     xmlMutexUnlock(xmlThrDefMutex);
 }
 
+/**
+ * xmlCleanupGlobals:
+ *
+ * Additional cleanup for multi-threading
+ */
+void xmlCleanupGlobals(void)
+{
+    xmlResetError(&xmlLastError);
+
+    if (xmlThrDefMutex != NULL) {
+       xmlFreeMutex(xmlThrDefMutex);
+       xmlThrDefMutex = NULL;
+    }
+    __xmlGlobalInitMutexDestroy();
+}
+
 /**
  * DOC_DISABLE : we ignore missing doc for the xmlThrDef functions,
  *               those are really internal work
diff --git a/parser.c b/parser.c
index 16a5cf69..1bc37137 100644
--- a/parser.c
+++ b/parser.c
@@ -14751,7 +14751,6 @@ xmlCleanupParser(void) {
     xmlSchemaCleanupTypes();
     xmlRelaxNGCleanupTypes();
 #endif
-    xmlResetLastError();
     xmlCleanupGlobals();
     xmlCleanupThreads(); /* must be last if called not from the main thread */
     xmlCleanupMemory();


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]