Reusing a curl handle leaks memory
| Bug #45161 | Reusing a curl handle leaks memory | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Submitted: | 2008-06-03 15:04 UTC | Modified: | 2008-12-17 14:20 UTC |
|
||||||||||
| From: | humbads at alum dot mit dot edu | Assigned: | ||||||||||||
| Status: | Closed | Package: | cURL related | |||||||||||
| PHP Version: | 5CVS, 6CVS (2008-12-08) | OS: | * | |||||||||||
| Private report: | No | CVE-ID: | None | |||||||||||
[2008-06-03 15:04 UTC] humbads at alum dot mit dot edu
Description:
------------
Reusing a curl handle for multiple requests leaks memory. It leaks about 100 bytes per request. This is a problem when making a large number of requests using the same handle. Libcurl documentation says to always reuse the handle when possible in order to reuse connections. The bug occurs on Windows XP/IIS and Apache/FreeBSD 6.2.
Reproduce code:
---------------
<?php
// Reuse curl handle memory leak test
$ch = curl_init();
$startmem = memory_get_usage();
for($i = 0; $i < 100; $i++) {
$fp = fopen('/dev/null', "w");
curl_setopt($ch, CURLOPT_URL,
'http://debug.atensoftware.com/r.php?echo='.rand());
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_exec($ch);
fclose($fp);
unset($fp);
print "$i-mem: ".(memory_get_usage() - $startmem)." bytes\n";
}
?>
Expected result:
----------------
The memory usage should not increase after each request.
Patches
Pull Requests
History
AllCommentsChangesGit/SVN commits
[2008-06-03 16:07 UTC] humbads at alum dot mit dot edu
Below is the r.php script. When testing this bug report, please use this script (or some other URL) so my poor server does not get hammered. <?php // This script runs a variable amount of time // and generates a variable amount of data // Output a random number of blank space $s = microtime(true); $m = rand(100,200); $bytes = 0; for($i = 0; $i < $m; $i++) { $message = " \n"; print $message; $bytes += strlen($message); usleep(10); } // Print time taken and the value of the "echo" parameter print isset($_REQUEST['echo']) ? 'echo: '.$_REQUEST['echo'].' ' : ""; print $bytes.' bytes '; print " in "; print round(microtime(true) - $s, 4)." seconds"; exit(); ?>[2008-06-03 19:24 UTC] humbads at alum dot mit dot edu
[2008-06-22 22:06 UTC] daniel at haxx dot se
[2008-08-15 15:37 UTC] jani@php.net
[2008-12-11 06:03 UTC] magicaltux@php.net
[2008-12-11 13:51 UTC] magicaltux@php.net
[2008-12-17 14:20 UTC] jani@php.net