From ec59953f4cb34c15cac4d98f587094556860847c Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Thu, 17 Sep 2015 03:14:14 +0200 Subject: [PATCH] [EventDispatcher] fix memory leak in a getListeners --- .../Component/EventDispatcher/EventDispatcher.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/EventDispatcher/EventDispatcher.php b/src/Symfony/Component/EventDispatcher/EventDispatcher.php index a2435e9978..67097e5662 100644 --- a/src/Symfony/Component/EventDispatcher/EventDispatcher.php +++ b/src/Symfony/Component/EventDispatcher/EventDispatcher.php @@ -61,6 +61,10 @@ class EventDispatcher implements EventDispatcherInterface public function getListeners($eventName = null) { if (null !== $eventName) { + if (!isset($this->listeners[$eventName])) { + return array(); + } + if (!isset($this->sorted[$eventName])) { $this->sortListeners($eventName); } @@ -177,9 +181,7 @@ class EventDispatcher implements EventDispatcherInterface { $this->sorted[$eventName] = array(); - if (isset($this->listeners[$eventName])) { - krsort($this->listeners[$eventName]); - $this->sorted[$eventName] = call_user_func_array('array_merge', $this->listeners[$eventName]); - } + krsort($this->listeners[$eventName]); + $this->sorted[$eventName] = call_user_func_array('array_merge', $this->listeners[$eventName]); } }