Bug #81017 [NEW]: PharData memory leak
From: jon dot johnson at ucsf dot edu
Operating system: PHP Docker / OSX 10.15.7
PHP version: 8.0.5
Package: PHAR related
Bug Type: Bug
Bug description:PharData memory leak
Description:
------------
When working with a tar file using PharData memory increases and is not
released. I first noticed this when using PharData::extractTo(), but it
is more easily reproduced with PharData::addEmptyDir() as I've done
below. It seems to be relative to to the size fo the archive, but I
didn't confirm this.
Seems to exist in all versions of PHP, tested with:
docker container run --rm -v $(pwd):/test/ php:5-cli php /test/test.php
docker container run --rm -v $(pwd):/test/ php:7-cli php /test/test.php
docker container run --rm -v $(pwd):/test/ php:8-cli php /test/test.php
and got the same result.
Test script:
---------------
<?php
echo 'Start: ' . memory_get_usage() . "\n\n";
for ($i = 0; $i < 10; $i++) {
$path = __DIR__ . DIRECTORY_SEPARATOR . $i . '.tar';
$phar = new PharData($path);
$phar->addEmptyDir('test');
unset($phar);
unlink($path);
echo "After ${i}: " . memory_get_usage() . "\n";
}
gc_collect_cycles();
echo "\nEnd: " . memory_get_usage() . "\n";
Expected result:
----------------
I would expect each iteration fo the loop to be self contained (even
without the manual steps to unset and unlink) and that memory
consumption would be constant for this script no matter how many
iterations were run.
Actual result:
--------------
php test.php
Start: 398248
After 0: 411936
After 1: 424968
After 2: 438000
After 3: 451032
After 4: 464064
After 5: 477096
After 6: 490128
After 7: 503160
After 8: 516512
After 9: 529544
End: 529504
--
Edit bug report at https://bugs.php.net/bug.php?id=81017&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=81017&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=81017&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=81017&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=81017&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=81017&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=81017&r=support
Expected behavior: https://bugs.php.net/fix.php?id=81017&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=81017&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=81017&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=81017&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=81017&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=81017&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=81017&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=81017&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=81017&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=81017&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=81017&r=mysqlcfg
Thread (6 messages)
- jon dot johnson at ucsf dot edu