From:             david at acz dot org
Operating system: SLES 10 x86_64
PHP version:      5.2.5
PHP Bug Type:     cURL related
Bug description:  curl CURLOPT_INFILE leaks handle reference

Description:
------------
File handles are normally closed automatically when the reference count
hits zero.  For example, if you fopen() something in a function and only
assign it to a local variable, the file is closed when the function
returns.

CURLOPT_INFILE breaks this behavior.  Presumably, the curl resource
destructor does not decrement the reference count for the file handle.  

Reproduce code:
---------------
<?
    $name = tempnam("/tmp", "phpbug");
    $n = count(scandir("/proc/self/fd"));

    test_simple($name);
    var_dump(count(scandir("/proc/self/fd")) == $n);

    test_curl($name, true);
    var_dump(count(scandir("/proc/self/fd")) == $n);

    test_curl($name, false);
    var_dump(count(scandir("/proc/self/fd")) == $n);

    function test_simple($name)
    {
        $fp = fopen($name, "r");
    }

    function test_curl($name, $close)
    {
        $fp = fopen($name, "r");
        $c = curl_init();
        curl_setopt($c, CURLOPT_PUT, true);
        curl_setopt($c, CURLOPT_INFILE, $fp);
        curl_setopt($c, CURLOPT_INFILESIZE, 0);
        curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
        curl_exec($c);
        curl_close($c);
        if ($close)
            fclose($fp);
    }
?>


Expected result:
----------------
bool(true)
bool(true)
bool(true)


Actual result:
--------------
bool(true)
bool(true)
bool(false)


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

Reply via email to