Skip to content

Commit

Permalink
[Translation] fix memoryleak in PhpFileLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Dec 10, 2019
1 parent 0be2534 commit 539bd22
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion Loader/PhpFileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,25 @@
*/
class PhpFileLoader extends FileLoader
{
private static $cache = [];

/**
* {@inheritdoc}
*/
protected function loadResource($resource)
{
return require $resource;
if ([] === self::$cache && \function_exists('opcache_invalidate') && filter_var(ini_get('opcache.enable'), FILTER_VALIDATE_BOOLEAN) && (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) || filter_var(ini_get('opcache.enable_cli'), FILTER_VALIDATE_BOOLEAN))) {
self::$cache = null;
}

if (null === self::$cache) {
return require $resource;
}

if (isset(self::$cache[$resource])) {
return self::$cache[$resource];
}

return self::$cache[$resource] = require $resource;
}
}

0 comments on commit 539bd22

Please sign in to comment.