Closed UCIS closed 4 years ago
Confirmed in the PHP docs:
Caution: In addition to calling xml_parser_free() when the parsing is finished, as of PHP 7.0.0 it is necessary to also explicitly unset the reference to parser to avoid memory leaks, if the parser resource is referenced from an object, and this object references that parser resource.
I agree with the assessment, whatever the original intent it doesn't look like we're using this right now so this seems like the best resolution.
The XML parser callback combined with the class level reference to the XML parser create a reference loop which can not be resolved by the PHP garbage collector. Therefore to prevent memory leaks either the class level reference should be cleaned (or not exist at all), or the parser callbacks should be unset (NULL) during cleanup. Just removing the class level reference, which as far as I can tell is not used anywhere, seems to be the easiest way.
Test case demonstrating the XML parser memory leak:
The bug affects PHP7.1 and 7.2, and is probably something that should be fixed in PHP, but that will probably take a lot more time than this simple fix.