Fix #670: Add additional checks before attempting to close curl handles

This commit is contained in:
Zach Borboa
2021-06-10 20:15:53 -04:00
parent 1b5989f9e9
commit 5425310a53
4 changed files with 8 additions and 10 deletions
+3 -3
View File
@@ -212,10 +212,10 @@ class Curl
*/
public function close()
{
if ($this->curl !== null) {
if (is_resource($this->curl) || $this->curl instanceof \CurlHandle) {
curl_close($this->curl);
$this->curl = null;
}
$this->curl = null;
$this->options = null;
$this->jsonDecoder = null;
$this->jsonDecoderArgs = null;
@@ -1459,7 +1459,7 @@ class Curl
*/
public function reset()
{
if (function_exists('curl_reset') && $this->curl !== null) {
if (function_exists('curl_reset') && (is_resource($this->curl) || $this->curl instanceof \CurlHandle)) {
curl_reset($this->curl);
} else {
$this->curl = curl_init();
+2 -2
View File
@@ -393,10 +393,10 @@ class MultiCurl
$curl->close();
}
if ($this->multiCurl !== null) {
if (is_resource($this->multiCurl) || $this->multiCurl instanceof \CurlMultiHandle) {
curl_multi_close($this->multiCurl);
$this->multiCurl = null;
}
$this->multiCurl = null;
}
/**
+2 -4
View File
@@ -3023,11 +3023,9 @@ class CurlTest extends \PHPUnit\Framework\TestCase
public function testClose()
{
$test = new Test();
$curl = $test->curl;
$curl->setHeader('X-DEBUG-TEST', 'post');
$curl = new Curl();
$curl->post(Test::TEST_URL);
$this->assertNotNull($curl->curl);
$this->assertTrue(is_object($curl->curl) || is_resource($curl->curl));
$curl->close();
$this->assertNull($curl->curl);
}
+1 -1
View File
@@ -2977,7 +2977,7 @@ class MultiCurlTest extends \PHPUnit\Framework\TestCase
$multi_curl = new MultiCurl();
$multi_curl->addGet(Test::TEST_URL);
$multi_curl->start();
$this->assertNotNull($multi_curl->multiCurl);
$this->assertTrue(is_object($multi_curl->multiCurl) || is_resource($multi_curl->multiCurl));
$multi_curl->close();
$this->assertNull($multi_curl->multiCurl);
}