|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2003-11-18 02:20 UTC] helly@php.net
[2003-11-18 02:22 UTC] helly@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 11:00:01 2025 UTC |
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 ===