Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 535cf50

Browse files
committed
merged branch fabpot/firewall-leaks (PR #8946)
This PR was merged into the 2.2 branch. Discussion ---------- [Security] fixed a leak in the ContextListener | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a Trying to fix leaks when using the same Kernel to handle several requests in a row without resetting the Container or shutting down the Kernel. Commits ------- 899f176 [Security] fixed a leak in ExceptionListener 2fd8a7a [Security] fixed a leak in the ContextListener
2 parents c753d68 + 899f176 commit 535cf50

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/Symfony/Component/Security/Http/Firewall/ContextListener.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class ContextListener implements ListenerInterface
3838
private $logger;
3939
private $userProviders;
4040
private $dispatcher;
41+
private $registered;
4142

4243
public function __construct(SecurityContextInterface $context, array $userProviders, $contextKey, LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null)
4344
{
@@ -65,8 +66,9 @@ public function __construct(SecurityContextInterface $context, array $userProvid
6566
*/
6667
public function handle(GetResponseEvent $event)
6768
{
68-
if (null !== $this->dispatcher && HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
69+
if (!$this->registered && null !== $this->dispatcher && HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
6970
$this->dispatcher->addListener(KernelEvents::RESPONSE, array($this, 'onKernelResponse'));
71+
$this->registered = true;
7072
}
7173

7274
$request = $event->getRequest();

src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ public function register(EventDispatcherInterface $dispatcher)
7676
*/
7777
public function onKernelException(GetResponseForExceptionEvent $event)
7878
{
79+
// we need to remove ourselves as the exception listener can be
80+
// different depending on the Request
81+
$event->getDispatcher()->removeListener(KernelEvents::EXCEPTION, array($this, 'onKernelException'));
82+
7983
$exception = $event->getException();
8084
$request = $event->getRequest();
8185

0 commit comments

Comments
 (0)