|  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
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
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.
Block user comment
Status: Assign to:
Bug Type:
From: david at acz dot org
New email:
PHP Version: OS:


 [2008-04-30 01:05 UTC] david at acz dot org
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"));

    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);
        if ($close)

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


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

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-2021 The PHP Group
All rights reserved.
Last updated: Fri Jan 22 04:01:23 2021 UTC