Bug #81251 [NEW]: Memory leak with datetime, serialization, and require
| From: | lyrixx at lyrixx dot info | Date: | Mon, 12 Jul 2021 10:05:03 +0000 |
| Subject: | Bug #81251 [NEW]: Memory leak with datetime, serialization, and require | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-234964@lists.php.net to get a copy of this message | ||
From: lyrixx at lyrixx dot info
Operating system: linux
PHP version: 8.0.8
Package: *General Issues
Bug Type: Bug
Bug description:Memory leak with datetime, serialization, and require
Description:
------------
When one require a PHP script, that unserialize some data with an
instance of DateTime in it, a memory leak occurs
Test script:
---------------
<?php
class Foobar
{
public function __construct(
// If this property is removed => No leak
public DateTime $d,
) {
}
}
for ($i=0; $i < 10000; $i++) {
$foobar = new Foobar(new \DateTime());
// 1. Leak when "require" is involved
$file = '/tmp/test-serialized.php';
file_put_contents($file, sprintf("<?php return
unserialize(base64_decode('%s'));\n",
base64_encode(serialize($foobar))));
$o = require $file;
// 2. No leak in this case
// unserialize(serialize($foobar));
if ($i % 1000 === 0) {
printf("%.2fMb\n", memory_get_usage() / 1024 / 1024);
}
}
Expected result:
----------------
0.38Mb
0.38Mb
0.38Mb
0.38Mb
0.38Mb
0.38Mb
0.38Mb
0.38Mb
0.38Mb
0.38Mb
Actual result:
--------------
0.38Mb
0.66Mb
0.90Mb
1.23Mb
1.47Mb
1.87Mb
2.11Mb
2.36Mb
2.60Mb
3.16Mb
--
Edit bug report at https://bugs.php.net/bug.php?id=81251&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=81251&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=81251&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=81251&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=81251&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=81251&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=81251&r=support
Expected behavior: https://bugs.php.net/fix.php?id=81251&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=81251&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=81251&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=81251&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=81251&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=81251&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=81251&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=81251&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=81251&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=81251&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=81251&r=mysqlcfg