forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Track created curl_slist structs by option so they can be updated in …
…situ. At present, when curl_setopt() is called with an option that requires the creation of a curl_slist, we simply push the new curl_slist onto a list to be freed when the curl handle is freed. This avoids a memory leak, but means that repeated calls to curl_setopt() on the same handle with the same option wastes previously allocated memory on curl_slist structs that will no longer be read. This commit changes the zend_llist that was previously used to track the lists to a HashTable keyed by the option number, which means that we can simply update the hash table each time curl_setopt() is called. Fixes bug #65458 (curl memory leak).
- Loading branch information
Showing
4 changed files
with
38 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--TEST-- | ||
Bug #65458 (curl memory leak) | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded('curl')) exit("skip curl extension not loaded"); | ||
?> | ||
--FILE-- | ||
<?php | ||
$ch = curl_init(); | ||
$init = memory_get_usage(); | ||
for ($i = 0; $i < 10000; $i++) { | ||
curl_setopt($ch, CURLOPT_HTTPHEADER, [ "SOAPAction: getItems" ]); | ||
} | ||
|
||
$preclose = memory_get_usage(); | ||
curl_close($ch); | ||
|
||
// This is a slightly tricky heuristic, but basically, we want to ensure | ||
// $preclose - $init has a delta in the order of bytes, not megabytes. Given | ||
// the number of iterations in the loop, if we're wasting memory here, we | ||
// should have megs and megs of extra allocations. | ||
var_dump(($preclose - $init) < 10000); | ||
?> | ||
--EXPECT-- | ||
bool(true) |