[libxml2] Call xmlCleanupParser on ELF destruction



commit 9fa3200cb366c726f7c8ef234282603bb9e8816d
Author: Samuel Thibault <samuel thibault ens-lyon org>
Date:   Tue Mar 31 23:18:25 2020 +0200

    Call xmlCleanupParser on ELF destruction
    
    Fixes #153.

 configure.ac | 10 ++++++++++
 parser.c     | 11 ++++++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)
---
diff --git a/configure.ac b/configure.ac
index 09418af2..5f95fee0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -641,6 +641,16 @@ else
       [Type cast for the send() function 2nd arg])
 fi
 
+dnl Checking whether __attribute__((destructor)) is accepted by the compiler
+AC_MSG_CHECKING([whether __attribute__((destructor)) is accepted])
+AC_TRY_COMPILE2([
+void __attribute__((destructor))
+f(void) {}], [], [
+  AC_MSG_RESULT(yes)
+  AC_DEFINE([ATTRIBUTE_DESTRUCTOR], [1],[Define if __attribute__((destructor)) is accepted])],[
+  AC_MSG_RESULT(no)])
+
+
 dnl ***********************Checking for availability of IPv6*******************
 
 AC_MSG_CHECKING([whether to enable IPv6])
diff --git a/parser.c b/parser.c
index 072eb22d..4ea8e84b 100644
--- a/parser.c
+++ b/parser.c
@@ -14599,7 +14599,7 @@ xmlInitParser(void) {
     if (xmlParserInitialized != 0)
        return;
 
-#if defined(WIN32) && (!defined(LIBXML_STATIC) || defined(LIBXML_STATIC_FOR_DLL))
+#if defined(_WIN32) && (!defined(LIBXML_STATIC) || defined(LIBXML_STATIC_FOR_DLL))
        atexit(xmlCleanupParser);
 #endif
 
@@ -14681,6 +14681,15 @@ xmlCleanupParser(void) {
     xmlParserInitialized = 0;
 }
 
+#if defined(ATTRIBUTE_DESTRUCTOR) && !defined(LIBXML_STATIC) && \
+    !defined(_WIN32)
+static void
+__attribute__((destructor))
+xmlDestructor(void) {
+    xmlCleanupParser();
+}
+#endif
+
 /************************************************************************
  *                                                                     *
  *     New set (2.6.0) of simpler and more flexible APIs               *


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