mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-08-30 12:14:36 +00:00
Fix #670: Add additional checks before attempting to close curl handles
This commit is contained in:
+3
-3
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user