[libxml2] Fix memory leak when shared libxml.dll is unloaded
- From: Nick Wellnhofer <nwellnhof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libxml2] Fix memory leak when shared libxml.dll is unloaded
- Date: Tue, 11 Feb 2020 11:10:32 +0000 (UTC)
commit c7c526d6d0f605ed090f8fc1bbede9e439d3185c
Author: Kevin Puetz <PuetzKevinA JohnDeere com>
Date: Mon Jan 13 18:49:01 2020 -0600
Fix memory leak when shared libxml.dll is unloaded
When a multiple modules (process/plugins) all link to libxml2.dll
they will in fact share a single loaded instance of it.
It is unsafe for any of them to call xmlCleanupParser,
as this would deinitialize the shared state and break others that might
still have ongoing use.
However, on windows atexit is per-module (rather process-wide), so if used
*within* libxml2 it is possible to register a clean up when all users
are done and libxml2.dll is about to actually unload.
This allows multiple plugins to link with and share libxml2 without
a premature cleanup if one is unloaded, while still cleaning up if *all*
such callers are themselves unloaded.
parser.c | 4 ++++
1 file changed, 4 insertions(+)
---
diff --git a/parser.c b/parser.c
index 43a1a0ab..1ba988cf 100644
--- a/parser.c
+++ b/parser.c
@@ -14741,6 +14741,10 @@ xmlInitParser(void) {
if (xmlParserInitialized != 0)
return;
+#if defined(WIN32) && (!defined(LIBXML_STATIC) || defined(LIBXML_STATIC_FOR_DLL))
+ atexit(xmlCleanupParser);
+#endif
+
#ifdef LIBXML_THREAD_ENABLED
__xmlGlobalInitMutexLock();
if (xmlParserInitialized == 0) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]