php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49727 fclose is not enough to dereference file
Submitted: 2009-09-30 18:56 UTC Modified: 2009-09-30 21:39 UTC
From: ipseno at yahoo dot com Assigned:
Status: Closed Package: Filesystem function related
PHP Version: 5.3SVN-2009-09-30 (snap) OS: WIN XP SP3
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ipseno at yahoo dot com
New email:
PHP Version: OS:

 

 [2009-09-30 18:56 UTC] ipseno at yahoo dot com
Description:
------------
fclose is not enough to dereference file

Reproduce code:
---------------
This WORKED before:
.... php code here ....
	// The file that the transfer should be written to, $fp is open file handle in writing(binary) mode
	curl_setopt($this->ch, CURLOPT_FILE, $fp);

	// Store image to file
	curl_exec($this->ch);

	// Close /path/temp/image.tmp
	fclose($fp);

	// HERE IS A CATCH!
	rename(/path/temp/image.tmp, /path/temp/image.tmp.png);

Expected result:
----------------
To rename a file

Actual result:
--------------
NOW, it issues error and DOES NOT rename file:
Warning: rename(/path/temp/image.tmp, /path/temp/image.tmp.png) [function.rename]: No such file or directory in /path/script.php on line 53536440


FIX: adding unset()!
.... php code here ....
	unset($fp);
	
	// HERE IS A CATCH!
	rename(/path/temp/image.tmp, /path/temp/image.tmp.png);
	
Problem: In 5.2 it worked without unset($fp); code line!

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-09-30 19:56 UTC] iliaa@php.net
This bug has been fixed in SVN.

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.


 [2009-09-30 21:39 UTC] ipseno at yahoo dot com
Is it?
Well..., I've reproduced this code/bug with PHP Version 5.3.2-dev, buiilt at Sep 29 2009 18:56:42

Will then download latest snapshot...
 
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed Feb 01 06:05:54 2023 UTC