|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38591 Memory Leak when using pathinfo and DirectoryIterator __toString
Submitted: 2006-08-25 15:19 UTC Modified: 2006-12-31 21:23 UTC
From: rr at d2g dot org dot uk Assigned:
Status: Not a bug Package: *Directory/Filesystem functions
PHP Version: 5.1.5 OS: win XP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
38 + 33 = ?
Subscribe to this entry?

 [2006-08-25 15:19 UTC] rr at d2g dot org dot uk
When running the code below on PHP version 5.1.6. On what seems to be any directory with files in, have tested with my C:/ and C:/folder/.

The code below is run from the Command Line to recreate the issue.

This is only present when using __toString rather than ->getFileName() or ->getPathName functions of DirectoryIterator. 

A memory leak occours.

Reproduce code:



$CurrentDir = new DirectoryIterator("C:/");
	foreach($CurrentDir as $file)
		$tmp = pathinfo($file);	  	





Expected result:

Actual result:
Works, but has memory Leak.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-08-25 21:35 UTC]
Please try using this CVS snapshot:
For Windows:

 [2006-08-29 07:03 UTC] rr at d2g dot org dot uk
Still present when using CSV snapshot.
 [2006-08-29 10:08 UTC]
What do you mean by "memory leak" ?
 [2006-08-29 12:04 UTC] rr at d2g dot org dot uk
Every time the loop is executed the memory used by php increases by approx 4k. This happens even though everything is unset. So every loop the memory usage should return to the minimum amount but this doesn't happen the memory usage continues to increase.

To view the error, load windows taskman and view the memory usage of php when running this code. You should see it slowly increasing.
 [2006-08-29 12:09 UTC]
Duplicate of bug #33487.
 [2006-08-29 12:43 UTC] rr at d2g dot org dot uk
I'm not 100% convinced that they are the same issue. I think this is related to the implementation of the magic method __toString.

Mainly because if the line below,
		$tmp = pathinfo($file); 
is replaced with
		$tmp = pathinfo($file->__tostring());

The memory leak no longer seems present even though fundmentally these should be doing exactly the same thing. 

So I belive it is somthing to do with the implementation of the magic __toString() function.
 [2006-12-31 21:23 UTC]
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.

Dupe of bug #38604 (this one has more information), the issue 
is identical however.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 14 19:01:28 2024 UTC