Bug #73568 [Opn->Csd]: Using null coalescing operator with SplObjectStorage causes memory leak
| From: | laruence@php.net | Date: | Mon, 21 Nov 2016 05:19:10 +0000 |
| Subject: | Bug #73568 [Opn->Csd]: Using null coalescing operator with SplObjectStorage causes memory leak | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-205499@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=73568&edit=1
ID: 73568
Updated by: laruence@php.net
Reported by: tandre at ifwe dot co
Summary: Using null coalescing operator with SplObjectStorage
causes memory leak
-Status: Open
+Status: Closed
Type: Bug
Package: SPL related
Operating System: Linux
PHP Version: 7.0.13
-Assigned To:
+Assigned To: laruence
Block user comment: N
Private report: N
New Comment:
fix has been merged..
Previous Comments:
------------------------------------------------------------------------
[2016-11-21 00:00:16] tandre at ifwe dot co
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 this bug report at https://bugs.php.net/bug.php?id=73568&edit=1