#40711 [Asn->Bgs]: RecursiveIteratorIterator unable to successfully clean up after itself
| From: | helly@php.net | Date: | Sun, 04 Mar 2007 12:34:19 +0000 |
| Subject: | #40711 [Asn->Bgs]: RecursiveIteratorIterator unable to successfully clean up after itself | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-109858@lists.php.net to get a copy of this message | ||
ID: 40711
Updated by: helly@php.net
Reported By: hannes dot magnusson at gmail dot com
-Status: Assigned
+Status: Bogus
Bug Type: Reproducible crash
-Operating System: FreeBSD
+Operating System: *
-PHP Version: 5CVS-2007-03-03 (CVS)
+PHP Version: *
Assigned To: helly
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
First thanks for filing this because I found an error in the class
layout. RecursiveFilterIterator::accept must be abstract. And instead
you want to use ParentIterator (PI). Another issue is actually in your
code. RecursiveIteratorIterator (RII) does not return parents until you
specify so by changing its mode (for instance RII::SELF_FIRST). The next
issue in the code is that PI::getChildren returns a RecursiveIterator
(RI) since it calls RDI::geChildren. This is then passed to
PI::__construct becuase it needs to keep the structure. Now in you
rcode RFI::__construct you create another RDI. That is the ctor
receives a PI that contains an RDI instance and creates a new RDI from
it. While doing so the inner RDI is being rewound to its first element
which is ".". Now as far as I can tell there will be a recursion
somehow with this approach. For me it actually aborts with an exception
message like, too many open files.
Given the fact that we don't fix recursions I'd say this is expected
behavior. If you feel different reopen this report.
The correct code to get the directories is below:
<?php
class RDI extends RecursiveDirectoryIterator {}
class PI extends ParentIterator {}
class RII extends RecursiveIteratorIterator {}
$rii = new RII(new PI(new RDI($argv[1])), RII::SELF_FIRST);
foreach($rii as $f) {
echo "$f\n";
}
Previous Comments:
------------------------------------------------------------------------
[2007-03-03 17:25:55] hannes dot magnusson at gmail dot com
Description:
------------
Run the code below with reasonable low memory_limit on, for
instance, PHP5.2 source directory.
Reproduce code:
---------------
<?php
class rfi extends RecursiveFilterIterator {
public function __construct($path) {
parent::__construct(new RecursiveDirectoryIterator($path));
}
}
class rii extends RecursiveIteratorIterator {
}
$rii = new rii(new rfi("."));
foreach($rii as $obj) {
}
Actual result:
--------------
#0 0x081d6e23 in spl_RecursiveIteratorIterator_free_storage
(_object=0x850464c, tsrm_ls=0x84e82b0)
at /usr/src/php/5.2/ext/spl/spl_iterators.c:719
719 sub_iter->funcs->dtor(sub_iter
TSRMLS_CC);
[New LWP 100098]
(gdb) bt
#0 0x081d6e23 in spl_RecursiveIteratorIterator_free_storage
(_object=0x850464c, tsrm_ls=0x84e82b0)
at /usr/src/php/5.2/ext/spl/spl_iterators.c:719
#1 0x0836d384 in zend_objects_store_free_object_storage
(objects=0x84f2618, tsrm_ls=0x84e82b0)
at /usr/src/php/5.2/Zend/zend_objects_API.c:89
#2 0x0833d2db in shutdown_executor (tsrm_ls=0x84e82b0)
at /usr/src/php/5.2/Zend/zend_execute_API.c:299
#3 0x0834c77e in zend_deactivate (tsrm_ls=0x84e82b0)
at /usr/src/php/5.2/Zend/zend.c:860
#4 0x082f5354 in php_request_shutdown (dummy=0x0)
at /usr/src/php/5.2/main/main.c:1311
#5 0x083bd0d8 in main (argc=2, argv=0xbfbfe960)
at /usr/src/php/5.2/sapi/cli/php_cli.c:1294
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=40711&edit=1