Skip to content

Commit 09b979d

Browse files
committed
Avoid memory leak by registering shutdown function exactly 1 time
Fixes #2092
1 parent b01a485 commit 09b979d

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/PhpSpreadsheet/Reader/Security/XmlScanner.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,22 @@ class XmlScanner
1818

1919
private static $libxmlDisableEntityLoaderValue;
2020

21+
/**
22+
* @var bool
23+
*/
24+
private static $shutdownRegistered = false;
25+
2126
public function __construct($pattern = '<!DOCTYPE')
2227
{
2328
$this->pattern = $pattern;
2429

2530
$this->disableEntityLoaderCheck();
2631

2732
// A fatal error will bypass the destructor, so we register a shutdown here
28-
register_shutdown_function([__CLASS__, 'shutdown']);
33+
if (!self::$shutdownRegistered) {
34+
self::$shutdownRegistered = true;
35+
register_shutdown_function([__CLASS__, 'shutdown']);
36+
}
2937
}
3038

3139
public static function getInstance(Reader\IReader $reader)

0 commit comments

Comments
 (0)