From:             felix-php at 7val dot com
Operating system: Debian Linux (etch)
PHP version:      5.2.10
PHP Bug Type:     HTTP related
Bug description:  Curl: CURLOPT_FILE increases file handle refcount

Description:
------------
When passing an open, writable file handle to Curl as the CURLOPT_FILE 
option, the refcount to that file handle is increased without being 
decreased when calling curl_close.

Thus the file handle has to be closed TWICE to actually being flushed 
and closed. In the reproduce code the file handle is still a valid 
resource after the first call to fclose().

The bug is reproducable in PHP 5.2.10. In 5.2.9 the code works as 
expected.

In 5.2.10 in ext/curl/interface.c:1440 the call 
zend_list_addref(Z_LVAL_PP(zvalue));
was added. Maybe the problem origins here, if there is no corresponding 
delref in curl_close()?

Reproduce code:
---------------
$fh = fopen('curl.out', 'w');

$c = curl_init('http://example.com');
curl_setopt($c, CURLOPT_FILE, $fh);
curl_exec($c);

fclose($fh);
echo "content 1: ". file_get_contents('curl.out') ."\n";
if (is_resource($fh)) {
        echo "file still open -> wrong\n";
} else {
        echo "file closed -> correct\n";
        exit;
}
fclose($fh);
if (is_resource($fh)) {
        echo "file open 2\n";
}

curl_close($c);
echo "content 2: ". file_get_contents('curl.out') ."\n";


Expected result:
----------------
content 1: <HTML>
<HEAD>
  <TITLE>Example Web Page</TITLE>
</HEAD> 
[..]

file closed -> correct


Actual result:
--------------
content 1: 
file still open -> wrong
content 2: <HTML>
<HEAD>
  <TITLE>Example Web Page</TITLE>
</HEAD> 
[..]

-- 
Edit bug report at http://bugs.php.net/?id=48676&edit=1
-- 
Try a CVS snapshot (PHP 5.2):        
http://bugs.php.net/fix.php?id=48676&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):        
http://bugs.php.net/fix.php?id=48676&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):        
http://bugs.php.net/fix.php?id=48676&r=trysnapshot60
Fixed in CVS:                        
http://bugs.php.net/fix.php?id=48676&r=fixedcvs
Fixed in CVS and need be documented: 
http://bugs.php.net/fix.php?id=48676&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=48676&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=48676&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=48676&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=48676&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=48676&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=48676&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=48676&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=48676&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=48676&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=48676&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=48676&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=48676&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=48676&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=48676&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=48676&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=48676&r=mysqlcfg

Reply via email to