[libxml2] Reset last error in xmlCleanupGlobals



commit 89d9ef3ee83c6cd0b048b3dc8dabddfe690b5579
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 94f78ddf..2bc3db27 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         *
@@ -1122,3 +1108,19 @@ __xmlOutputBufferCreateFilenameValue(void) {
        return (&xmlGetGlobalState()->xmlOutputBufferCreateFilenameValue);
 }
 
+/**
+ * xmlCleanupGlobals:
+ *
+ * Additional cleanup for multi-threading
+ */
+void xmlCleanupGlobals(void)
+{
+    xmlResetError(&xmlLastError);
+
+    if (xmlThrDefMutex != NULL) {
+       xmlFreeMutex(xmlThrDefMutex);
+       xmlThrDefMutex = NULL;
+    }
+    __xmlGlobalInitMutexDestroy();
+}
+
diff --git a/parser.c b/parser.c
index 54c5b0c2..3aecf3e9 100644
--- a/parser.c
+++ b/parser.c
@@ -14753,7 +14753,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]