php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44866 curl CURLOPT_INFILE leaks handle reference
Submitted: 2008-04-30 01:05 UTC Modified: 2008-05-09 18:05 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: david at acz dot org Assigned:
Status: Not a bug Package: cURL related
PHP Version: 5.2.5 OS: SLES 10 x86_64
Private report: No CVE-ID: None
 [2008-04-30 01:05 UTC] david at acz dot org
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)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-05-05 23:04 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

The file will be closed at the end of the request.
 [2008-05-09 18:03 UTC] david at acz dot org
That does not help for long-running (e.g. CLI) scripts.
 [2008-05-09 18:05 UTC] david at acz dot org
That does not help for long running (e.g. CLI) scripts.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 13:01:29 2024 UTC