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
This commit is contained in:
Fabien Potencier 2013-09-06 20:18:09 +02:00
commit 535cf50c3a
2 changed files with 7 additions and 1 deletions

View File

@ -38,6 +38,7 @@ class ContextListener implements ListenerInterface
private $logger;
private $userProviders;
private $dispatcher;
private $registered;
public function __construct(SecurityContextInterface $context, array $userProviders, $contextKey, LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null)
{
@ -65,8 +66,9 @@ class ContextListener implements ListenerInterface
*/
public function handle(GetResponseEvent $event)
{
if (null !== $this->dispatcher && HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
if (!$this->registered && null !== $this->dispatcher && HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
$this->dispatcher->addListener(KernelEvents::RESPONSE, array($this, 'onKernelResponse'));
$this->registered = true;
}
$request = $event->getRequest();

View File

@ -76,6 +76,10 @@ class ExceptionListener
*/
public function onKernelException(GetResponseForExceptionEvent $event)
{
// we need to remove ourselves as the exception listener can be
// different depending on the Request
$event->getDispatcher()->removeListener(KernelEvents::EXCEPTION, array($this, 'onKernelException'));
$exception = $event->getException();
$request = $event->getRequest();