Avoid memory leak by registering shutdown function exactly 1 time

Fixes #2092
This commit is contained in:
Adrien Crivelli 2021-05-16 12:35:42 +09:00
parent b01a485f4f
commit 09b979defa
No known key found for this signature in database
GPG Key ID: 16D79B903B4B5874
1 changed files with 9 additions and 1 deletions

View File

@ -18,6 +18,11 @@ class XmlScanner
private static $libxmlDisableEntityLoaderValue;
/**
* @var bool
*/
private static $shutdownRegistered = false;
public function __construct($pattern = '<!DOCTYPE')
{
$this->pattern = $pattern;
@ -25,7 +30,10 @@ class XmlScanner
$this->disableEntityLoaderCheck();
// A fatal error will bypass the destructor, so we register a shutdown here
register_shutdown_function([__CLASS__, 'shutdown']);
if (!self::$shutdownRegistered) {
self::$shutdownRegistered = true;
register_shutdown_function([__CLASS__, 'shutdown']);
}
}
public static function getInstance(Reader\IReader $reader)