1
0
mirror of https://github.com/danog/amp.git synced 2024-11-26 20:15:00 +01:00

Free loop handle when destructing EventDriver

Relates to #177.
This commit is contained in:
Aaron Piotrowski 2018-04-08 13:20:27 -05:00
parent 3b12391529
commit 9b2fb76442
No known key found for this signature in database
GPG Key ID: ADD1EF783EDE9EEB

View File

@ -121,12 +121,21 @@ class EventDriver extends Driver {
*/ */
public function __destruct() { public function __destruct() {
foreach ($this->events as $event) { foreach ($this->events as $event) {
$event->free(); if ($event !== null) { // Events may have been nulled in extension depending on destruct order.
$event->free();
}
} }
// Unset here, otherwise $event->del() fails with a warning, because __destruct order isn't defined. // Unset here, otherwise $event->del() fails with a warning, because __destruct order isn't defined.
// See https://github.com/amphp/amp/issues/159. // See https://github.com/amphp/amp/issues/159.
$this->events = []; $this->events = [];
// Manually free the loop handle to fully release loop resources.
// See https://github.com/amphp/amp/issues/177.
if ($this->handle !== null) {
$this->handle->free();
$this->handle = null;
}
} }
/** /**