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.
* PHP-8.4: curl: Prevent a CurlMultiHandle from holding onto a CurlHandle if `add_handle` fails (php#16302)
- Loading branch information
Showing
2 changed files
with
58 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--TEST-- | ||
curl_multi_add_handle does not hold onto the handle on failure | ||
--EXTENSIONS-- | ||
curl | ||
--FILE-- | ||
<?php | ||
|
||
class MyClass { | ||
public function __destruct() { | ||
echo __METHOD__, PHP_EOL; | ||
} | ||
} | ||
|
||
$urls = [ | ||
"file://".__DIR__."/curl_testdata1.txt", | ||
"file://".__DIR__."/curl_testdata2.txt", | ||
]; | ||
|
||
$mh = curl_multi_init(); | ||
|
||
$toRemove = []; | ||
foreach ($urls as $url) { | ||
$ch = curl_init($url); | ||
curl_setopt($ch, CURLOPT_PRIVATE, new MyClass()); | ||
|
||
if (curl_multi_add_handle($mh, $ch) == CURLM_OK) { | ||
$toRemove[] = $ch; | ||
} | ||
if (curl_multi_add_handle($mh, $ch) == CURLM_OK) { | ||
$toRemove[] = $ch; | ||
} | ||
|
||
unset($ch); | ||
} | ||
|
||
echo "Removing", PHP_EOL; | ||
foreach ($toRemove as $i => $ch) { | ||
curl_multi_remove_handle($mh, $ch); | ||
unset($ch); | ||
unset($toRemove[$i]); | ||
} | ||
echo "Removed", PHP_EOL; | ||
|
||
?> | ||
--EXPECTF-- | ||
Removing | ||
MyClass::__destruct | ||
MyClass::__destruct | ||
Removed |