php-src/ext/curl/tests/curl_share_basic.phpt
Nikita Popov b4a2a9662b Retain reference to share handle from curl handle
Not keeping a reference will not result in use after free, because
curl protects against it, but it will result in a memory leak,
because curl_share_cleanup() will fail. We should make sure that
the share handle object stays alive as long as the curl handles
use it.
2020-11-11 11:56:03 +01:00

29 lines
634 B
PHP

--TEST--
Basic curl_share test
--FILE--
<?php
$sh = curl_share_init();
$ch1 = curl_init();
curl_setopt($ch1, CURLOPT_URL, 'file://' . __DIR__ . '/curl_testdata1.txt');
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch1, CURLOPT_SHARE, $sh);
$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_URL, 'file://' . __DIR__ . '/curl_testdata2.txt');
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch2, CURLOPT_SHARE, $sh);
// Make sure nothing bad handles if the share handle is unset early.
unset($sh);
var_dump(curl_exec($ch1));
var_dump(curl_exec($ch2));
?>
--EXPECT--
string(6) "CURL1
"
string(6) "CURL2
"