Commit a11e8b1b authored by Martin Szulecki's avatar Martin Szulecki

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.
parent 8ed89366
......@@ -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();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment