8000 [SecurityBundle] Fixed a memory leak in SecurityBundle\Security\FirewallMap by udavka · Pull Request #22605 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[SecurityBundle] Fixed a memory leak in SecurityBundle\Security\FirewallMap #22605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed on review commments
  • Loading branch information
udavka committed May 13, 2017
commit 2e9e6a23c840fdb401a61f4a97bc3dc7974a1e9f
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@
<argument type="service" id="event_dispatcher" />
</service>

<service id="security.firewall.map" class="Symfony\Bundle\SecurityBundle\Security\FirewallMap" public="false">
<service id="security.firewall.map" class="Symfony\Bundle\SecurityBundle\Security\FirewallMap">
<tag name="kernel.finish_request" />
<argument type="service" id="service_container" />
<argument type="collection" />
</service>
Expand Down
27 changes: 19 additions & 8 deletions src/Symfony/Bundle/SecurityBundle/Security/FirewallMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Bundle\SecurityBundle\Security;

use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
use Symfony\Component\Security\Http\FirewallMapInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\DependencyInjection\ContainerInterface;
Expand Down Expand Up @@ -49,14 +50,6 @@ public function getListeners(Request $request)
return $context->getContext();
}

/**
* {@inheritdoc}
*/
public function detachListeners(Request $request)
{
unset($this->contexts[$request]);
}

/**
* @return FirewallConfig|null
*/
Expand All @@ -83,4 +76,22 @@ private function getFirewallContext(Request $request)
}
}
}

/**
* @param FinishRequestEvent $event
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To remove, as it does not bring anything more than the signature.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

*/
public function onKernelFinishRequest(FinishRequestEvent $event)
{
$this->detachListeners($event->getRequest());
}

/**
* Cleans up the internal state of the firewall map.
*
* @param Request $request
*/
private function detachListeners(Request $request)
{
unset($this->contexts[$request]);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO you should directly unset the request in the onKernelFinishRequest method, that would make one less method call...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

}
7 changes: 0 additions & 7 deletions src/Symfony/Component/Security/Http/FirewallMapInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,4 @@ interface FirewallMapInterface
* @return array of the format array(array(AuthenticationListener), ExceptionListener)
*/
public function getListeners(Request $request);

/**
* Cleans up the internal state of the firewall map.
*
* @param Request $request
*/
public function detachListeners(Request $request);
}
39 changes: 0 additions & 39 deletions src/Symfony/Component/Security/Http/Tests/FirewallMapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,43 +115,4 @@ public function testGetListenersWithNoMatchingEntry()
$this->assertEquals(array(), $listeners);
$this->assertNull($exception);
}

public function testDetachListeners()
{
$map = new FirewallMap();

$request1 = new Request(array('id' => 1));
$matchingMatcher1 = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestMatcher')->getMock();
$matchingMatcher1
->method('matches')
->will($this->returnCallback(function (Request $request) {
return $request->query->get('id') === 1;
}))
;

$request2 = new Request(array('id' => 2));
$matchingMatcher2 = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestMatcher')->getMock();
$matchingMatcher2
->method('matches')
->will($this->returnCallback(function (Request $request) {
return $request->query->get('id') === 2;
}))
;

$theListener = $this->getMockBuilder('Symfony\Component\Security\Http\Firewall\ListenerInterface')->getMock();
$theException = $this->getMockBuilder('Symfony\Component\Security\Http\Firewall\ExceptionListener')->disableOriginalConstructor()->getMock();

$map->add($matchingMatcher1, array($theListener), $theException);
$map->add($matchingMatcher2, array($theListener), $theException);

$map->detachListeners($request1);

list($listeners, $exception) = $map->getListeners($request1);
$this->assertEquals(array(), $listeners);
$this->assertNull($exception);

list($listeners, $exception) = $map->getListeners($request2);
$this->assertEquals(array($theListener), $listeners);
$this->assertEquals($theException, $exception);
}
}
0