summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2015-01-23 15:05:38 +0100
committerGravatar Martin Szulecki2015-01-23 15:05:38 +0100
commita11e8b1b9a7661a19a75ef4ffbff99e7adb1ec8d (patch)
tree4b0b92e2d7910b5ca4a01b5fb2075d746681c29d
parent8ed89366e45d594205cf6401ffe6852921ef2484 (diff)
downloadlibplist-a11e8b1b9a7661a19a75ef4ffbff99e7adb1ec8d.tar.gz
libplist-a11e8b1b9a7661a19a75ef4ffbff99e7adb1ec8d.tar.bz2
xplist: Plug memory leak by cleaning up libxml2's parser after use
This is actually considered bad practice. However, it appears this memory leak is otherwise not possible to fix due to a design flaw in how libxml2 handles the lifecycle of it's XML parser. We'll let the community test this in production now and decide. In our tests this change had no drawbacks except fixing the last known memory leak in libplist.
-rw-r--r--src/xplist.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/xplist.c b/src/xplist.c
index e368b8b..1ee0138 100644
--- a/src/xplist.c
+++ b/src/xplist.c
@@ -556,6 +556,14 @@ PLIST_API void plist_to_xml(plist_t plist, char **plist_xml, uint32_t * length)
setlocale(LC_NUMERIC, saved_locale);
free(saved_locale);
}
+
+ /* free memory from parser initialization */
+ xmlCleanupCharEncodingHandlers();
+ xmlDictCleanup();
+ xmlResetLastError();
+ xmlCleanupGlobals();
+ xmlCleanupThreads();
+ xmlCleanupMemory();
}
static xmlParserInputPtr plist_xml_external_entity_loader(const char *URL, const char *ID, xmlParserCtxtPtr ctxt)
@@ -576,4 +584,12 @@ PLIST_API void plist_from_xml(const char *plist_xml, uint32_t length, plist_t *
xml_to_node(root_node, plist);
xmlFreeDoc(plist_doc);
}
+
+ /* free memory from parser initialization */
+ xmlCleanupCharEncodingHandlers();
+ xmlDictCleanup();
+ xmlResetLastError();
+ xmlCleanupGlobals();
+ xmlCleanupThreads();
+ xmlCleanupMemory();
}