Skip to content

Commit 43b291e

Browse files
soulseekahschlessera
authored andcommitted
Prevent cURL transport from leaking on Exception
The `CURLOPT_HEADERFUNCTION` and `CURLOPT_WRITEFUNCTION` options are not being reset if a cURL handle error occurs (which throws a `Requests_Exception` and stops execution). The destructor is not called due to lingering instance method callbacks in the two options. Move `CURLOPT_HEADERFUNCTION` and `CURLOPT_WRITEFUNCTION` cleanup before any exceptions can happen.
1 parent 38b5686 commit 43b291e

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/Transport/Curl.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,14 @@ public function request($url, $headers = array(), $data = array(), $options = ar
200200
$response = $this->response_data;
201201
}
202202

203-
$this->process_response($response, $options);
203+
if (true === $options['blocking']) {
204+
// Need to remove the $this reference from the curl handle.
205+
// Otherwise \WpOrg\Requests\Transport\Curl wont be garbage collected and the curl_close() will never be called.
206+
curl_setopt($this->handle, CURLOPT_HEADERFUNCTION, null);
207+
curl_setopt($this->handle, CURLOPT_WRITEFUNCTION, null);
208+
}
204209

205-
// Need to remove the $this reference from the curl handle.
206-
// Otherwise \WpOrg\Requests\Transport\Curl won't be garbage collected and the curl_close() will never be called.
207-
curl_setopt($this->handle, CURLOPT_HEADERFUNCTION, null);
208-
curl_setopt($this->handle, CURLOPT_WRITEFUNCTION, null);
210+
$this->process_response($response, $options);
209211

210212
return $this->headers;
211213
}

0 commit comments

Comments
 (0)