#26257 [Csd]: Iterators leak memory
| From: | helly@php.net | Date: | Tue, 18 Nov 2003 07:22:54 +0000 |
| Subject: | #26257 [Csd]: Iterators leak memory | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-50606@lists.php.net to get a copy of this message | ||
ID: 26257
Updated by: helly@php.net
Reported By: adam at trachtenberg dot com
Status: Closed
Bug Type: Zend Engine 2 problem
Operating System: *
PHP Version: 5CVS-2003-11-14 (dev)
Assigned To: helly
New Comment:
Actually the problem had nothing to do with iterators. The real problem
was list() assigning to properties.
Previous Comments:
------------------------------------------------------------------------
[2003-11-18 02:20:24] helly@php.net
This bug has been fixed in CVS.
In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.
In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
Thank you for the report, and for helping us make PHP better.
------------------------------------------------------------------------
[2003-11-14 18:49:45] adam at trachtenberg dot com
Description:
------------
Iterators leak memory when assigning the results of
each() to object properties using a list(). When the
results are stored in local variables and then reassign,
no leak occurs.
Reproduce code:
---------------
class ai implements Iterator {
private $array;
function __construct() {
$this->array = array('foo', 'bar', 'baz');
}
function rewind() {
// empty
}
function hasMore() {
if (list($this->key, $this->current) = each($this->array)) {
# if (list($key, $current) = each($this->array)) {
# $this->key = $key;
# $this->current = $current;
return true;
} else {
return false;
}
}
function key() {
return 'key';
}
function current() {
return 'current';
}
function next() {
// empty
}
}
class a implements IteratorAggregate {
public function getIterator() {
return new ai();
}
}
$array = new a();
foreach ($array as $property => $value) {
print "$property: $value\n";
}
Expected result:
----------------
No memory leaks. Activate the commented code to see a
working example.
Actual result:
--------------
/usr/local/cvs/php/php-src/Zend/zend_API.c(1011) :
Freeing 0x00BC8AF8 (16 bytes), script=./
iterator_leak.php
Last leak repeated 2 times
/usr/local/cvs/php/php-src/Zend/zend_execute.c(3241) :
Freeing 0x00BC8300 (4 bytes), script=./iterator_leak.php
/usr/local/cvs/php/php-src/Zend/zend_variables.c(137) :
Actual location (location was relayed)
Last leak repeated 2 times
/usr/local/cvs/php/php-src/Zend/zend_execute.c(3238) :
Freeing 0x00BC82B0 (16 bytes), script=./
iterator_leak.php
Last leak repeated 2 times
=== Total 9 memory leaks detected ===
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=26257&edit=1