Bug #73568 [NEW]: Using null coalescing operator with SplObjectStorage causes memory leak

From: Date: Mon, 21 Nov 2016 00:00:19 +0000
Subject: Bug #73568 [NEW]: Using null coalescing operator with SplObjectStorage causes memory leak
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-205496@lists.php.net to get a copy of this message
From: tandre at ifwe dot co Operating system: Linux PHP version: 7.0.13 Package: SPL related Bug Type: Bug Bug description:Using null coalescing operator with SplObjectStorage causes memory leak Description: ------------ See https://github.com/php/php-src/pull/2215 for a description and a fix. The objects(keys) used for the null coalescing operator are leaked if the entry does not exist in the map. PHP 7.0.13(and 7.0.12, probably others) are affected, along with php 7.1.0RC6. (The null coalescing operator was introduced in 7.0) Test script: --------------- <?php $b = new stdClass(); $map = new SplObjectStorage(); var_export($map[$b] ?? null); // /usr/local/php-7.0.12-src/Zend/zend_objects.c(162) : Freeing 0x7F3957875A00 (40 bytes), script=/path/to/test.php Expected result: ---------------- No memory leaks. Null coalescing operator continues behaving equivalently to isset($hash[$obj]) ? $hash[$obj] : $default (which currently does not leak) Actual result: -------------- The return value of the coalescing operator was correct, but memory leaks are observed (visible in debug builds), of the form /usr/local/php-7.0.12-src/Zend/zend_objects.c(162) : Freeing 0x7F3957875A00 (40 bytes), script=/path/to/test.php -- Edit bug report at https://bugs.php.net/bug.php?id=73568&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=73568&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=73568&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=73568&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=73568&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=73568&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=73568&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=73568&r=needscript Try newer version: https://bugs.php.net/fix.php?id=73568&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=73568&r=support Expected behavior: https://bugs.php.net/fix.php?id=73568&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=73568&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=73568&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=73568&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=73568&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=73568&r=dst IIS Stability: https://bugs.php.net/fix.php?id=73568&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=73568&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=73568&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=73568&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=73568&r=mysqlcfg

« previous php.bugs (#205496) next »