php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: rr at d2g dot org dot uk
New email:
PHP Version: OS:

 

 [2006-08-25 15:19 UTC] rr at d2g dot org dot uk
Description:
------------
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:
---------------
<?php

set_time_limit(0);

while(true)
{

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

unset($tmp);
unset($file);
unset($CurrentDir);

sleep(1);

}


?>

Expected result:
----------------
Works.

Actual result:
--------------
Works, but has memory Leak.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-08-25 21:35 UTC] tony2001@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip


 [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] tony2001@php.net
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] tony2001@php.net
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] iliaa@php.net
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: Fri Apr 19 03:01:27 2024 UTC