Skip to content

Commit

Permalink
Check for custom free function in global destructor
Browse files Browse the repository at this point in the history
Calling a custom deallocation function in the global destructor could
cause all kinds of unexpected problems. See for example

    sparklemotion/nokogiri#2059

Only clean up if memory is managed with malloc/free.
  • Loading branch information
nwellnhof committed Aug 4, 2020
1 parent 8e7c20a commit 956534e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion parser.c
Expand Up @@ -14696,7 +14696,12 @@ xmlCleanupParser(void) {
static void
ATTRIBUTE_DESTRUCTOR
xmlDestructor(void) {
xmlCleanupParser();
/*
* Calling custom deallocation functions in a destructor can cause
* problems, for example with Nokogiri.
*/
if (xmlFree == free)
xmlCleanupParser();
}
#endif

Expand Down

0 comments on commit 956534e

Please sign in to comment.