Bug #81215 [NEW]: Possible memory leak with closure nested \array_filter()
From: berliozdavid at gmail dot com
Operating system: Fedora/Linux
PHP version: 8.0.8
Package: Performance problem
Bug Type: Bug
Bug description:Possible memory leak with closure nested \array_filter()
Description:
------------
With PHP80 using \array_filter() in a closure can lead to memory leak.
PHP74 is not affected.
Test script:
---------------
<?php
namespace Somewhere\On\Earth;
class Foo {
function leaking(array $array) {
$f = function ($array) {
return \array_filter($array, fn($item) => !is_null($item));
};
for (;;) {
$clone = (array) $array;
$res = $f($clone);
printf("memory: %d\n", \memory_get_usage());
unset($clone, $res);
}
}
function run() {
$array = array_combine(range(1, 1000, 2), array_fill(1, 500,
null));
$array += array_combine(range(2, 1000, 2), array_fill(1, 500,
true));
$this->leaking($array);
}
}
(new Foo())->run();
Expected result:
----------------
stable memory value.
Actual result:
--------------
increasing memory value.
--
Edit bug report at https://bugs.php.net/bug.php?id=81215&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=81215&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=81215&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=81215&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=81215&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=81215&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=81215&r=support
Expected behavior: https://bugs.php.net/fix.php?id=81215&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=81215&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=81215&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=81215&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=81215&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=81215&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=81215&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=81215&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=81215&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=81215&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=81215&r=mysqlcfg
Thread (10 messages)
- berliozdavid at gmail dot com