[php-src] Issue #8548: memory leak when using fopen with a stream wrapper

From: Date: Fri, 13 May 2022 12:10:21 +0000
Subject: [php-src] Issue #8548: memory leak when using fopen with a stream wrapper
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-241483@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/8548 Author: manueldimmler ### Description The following code takes up a lot of memory and keeps increasing in a endless loop: ```php #!/usr/bin/php <?php class Wrapper { public function stream_open(string $path, string $mode, int $options): bool { return true; } } $filename = tempnam(__DIR__, ''); touch($filename); $wrapper = new Wrapper(); $counter = 0; while ($counter < 1_000_000) { $counter++; stream_wrapper_register('symfony', Wrapper::class); fopen('symfony://' . $filename, 'r'); stream_wrapper_unregister('symfony'); } ``` ![memory_leak_01](https://user-images.githubusercontent.com/76745962/168278615-edca064b-5a0e-4b97-b225-e2e67960dc2e.PNG) With a small change, the problem disappears: ```php #!/usr/bin/php <?php class Wrapper { public function stream_open(string $path, string $mode, int $options): bool { return true; } } $filename = tempnam(__DIR__, ''); touch($filename); $wrapper = new Wrapper(); $counter = 0; stream_wrapper_register('symfony', Wrapper::class); while ($counter < 1_000_000) { $counter++; fopen('symfony://' . $filename, 'r'); } stream_wrapper_unregister('symfony'); ``` ![memory_leak_02](https://user-images.githubusercontent.com/76745962/168279139-3be2d313-1205-4342-8071-3bba9a7c3c99.PNG) The memory leak was described in the following ticket: https://github.com/symfony/symfony/issues/46256 ### PHP Version PHP 8.1.5 (cli) ### Operating System Ubuntu 20.04

« previous php.bugs (#241483) next »