php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31348 CachingIterator::rewind() leaks
Submitted: 2004-12-30 10:46 UTC Modified: 2005-01-25 23:38 UTC
From: tony2001 at phpclub dot net Assigned: helly
Status: Closed Package: SPL related
PHP Version: 5.0.3 OS: *
Private report: No CVE-ID:
 [2004-12-30 10:46 UTC] tony2001 at phpclub dot net
Description:
------------
CachingIterator::rewind() leaks some memory.
I can propose this small patch, but I'm almost sure it's not the real solution.

Index: spl_iterators.c
===================================================================
RCS file: /repository/php-src/ext/spl/spl_iterators.c,v
retrieving revision 1.61
diff -u -r1.61 spl_iterators.c
--- spl_iterators.c     29 Dec 2004 16:11:42 -0000      1.61
+++ spl_iterators.c     30 Dec 2004 09:43:14 -0000
@@ -752,7 +752,8 @@
        }
        if (intern->dit_type == DIT_CachingIterator || intern->dit_type == DIT_CachingRecursiveIterator) {
                if (intern->u.caching.zstr) {
-                       zval_ptr_dtor(&intern->u.caching.zstr);
+                       zval_dtor(intern->u.caching.zstr);
+                       FREE_ZVAL(intern->u.caching.zstr);
                        intern->u.caching.zstr = NULL;
                }
                if (intern->u.caching.zchildren) {

Reproduce code:
---------------
<?php
$a = Array("some","blah");
$i = new ArrayIterator($a);

$ci = new CachingIterator($i);

$ci->rewind();

echo "Done\n";
?>

Expected result:
----------------
Done

Actual result:
--------------
Done
/home/dev/php-src/ext/spl/spl_iterators.c(1276) :  Freeing 0x082E9064 (16 bytes), script=/www/index.php
/home/dev/php-src/Zend/zend_variables.h(45) :  Freeing 0x082E8E9C (5 bytes), script=/www/index.php
/home/dev/php-src/Zend/zend_variables.c(120) : Actual location (location was relayed)
=== Total 2 memory leaks detected ===

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-01-25 23:38 UTC] helly@php.net
This bug has been fixed in CVS.

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/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Wed Apr 23 18:01:55 2014 UTC