From: adam at trachtenberg dot com
Operating system: *
PHP version: 5CVS-2003-11-14 (dev)
PHP Bug Type: Zend Engine 2 problem
Bug description: Iterators leak memory
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 bug report at http://bugs.php.net/?id=26257&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=26257&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=26257&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=26257&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=26257&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=26257&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=26257&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=26257&r=support
Expected behavior: http://bugs.php.net/fix.php?id=26257&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=26257&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=26257&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=26257&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=26257&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=26257&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=26257&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=26257&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=26257&r=float