[php-src] Issue #9687: PHP-FPM memory leak when calling empty static function with object as parameter
| From: | sahl | Date: | Fri, 07 Oct 2022 10:05:46 +0000 |
| Subject: | [php-src] Issue #9687: PHP-FPM memory leak when calling empty static function with object as parameter | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-242541@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/9687
Author: sahl
### Description
When I run the following script:
```
<?php
// Ten loops
for ($i = 0; $i < 10; $i++) {
$test = new Test();
$test->test_function();
echo memory_get_usage()."\n";
}
class Test {
public $data = '';
public function __construct() {
}
public function test_function() {
// Generate 4 MB data inside the object
$this->data = str_repeat('a', 4*1024*1024);
self::test_function2($this);
}
public static function test_function2($object) {
//echo 'Hello'; // Enable this to prevent memory leak
return;
}
}
?>
```
from the command line interface I get the following output:
_4591128
4591160
4591160
4591160
4591160
4591160
4591160
4591160
4591160
4591160_
which is the expected output. (Memory use is constant).
When I run it through PHP-FPM I get this output:
_4553128
8751608
12950088
17148568
21347048
25545528
29744008
33942488
38140968
42339448_
...which indicate that memory is leaking.
If I enable the echo line, memory will not leak anymore.
Tested on PHP 8.1.2 running on Ubuntu Linux 22.04.1
(Sorry I cannot test on newest version, but I have looked through closed issues to see if someone
reported something similar).
### PHP Version
PHP 8.1.2
### Operating System
Ubuntu 22.04.1