Skip to content

Commit 34d01c1

Browse files
minor symfony#60934 [HttpKernel] Avoid memory leaks cache attribute, profiler listener (andrew-demb)
This PR was squashed before being merged into the 7.4 branch. Discussion ---------- [HttpKernel] Avoid memory leaks cache attribute, profiler listener | Q | A | ------------- | --- | Branch? | 7.4 | Bug fix? | no | New feature? | yes <!-- if yes, also update src/**/CHANGELOG.md --> | Deprecations? | no <!-- if yes, also update UPGRADE-*.md and src/**/CHANGELOG.md --> | Issues | | License | MIT <!-- 🛠️ Replace this text with a concise explanation of your change: - What it does and why it's needed - A simple example of how it works (include PHP, YAML, etc.) - If it modifies existing behavior, include a before/after comparison Contributor guidelines: - ✅ Add tests and ensure they pass - 🐞 Bug fixes must target the **lowest maintained** branch where they apply https://symfony.com/releases#maintained-symfony-branches - ✨ New features and deprecations must target the **feature** branch and must add an entry to the changelog file of the patched component: https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry - 🔒 Do not break backward compatibility: https://symfony.com/bc --> For the current moment, if the `onKernelTerminate` / `onKernelResponse` methods won't be called, the listener's state won't be reset between requests. ~~Please let me know if this should be considered as a new feature - to retarget PR to the 7.3 branch~~ ~~Similar to PR symfony#60933~~ Commits ------- 4e203f0 [HttpKernel] Avoid memory leaks cache attribute, profiler listener
2 parents 8a5de03 + 4e203f0 commit 34d01c1

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

src/Symfony/Bundle/FrameworkBundle/Resources/config/profiling.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
param('profiler_listener.only_main_requests'),
4040
])
4141
->tag('kernel.event_subscriber')
42+
->tag('kernel.reset', ['method' => '?reset'])
4243

4344
->set('console_profiler_listener', ConsoleProfilerListener::class)
4445
->args([

src/Symfony/Bundle/FrameworkBundle/Resources/config/web.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146

147147
->set('controller.cache_attribute_listener', CacheAttributeListener::class)
148148
->tag('kernel.event_subscriber')
149+
->tag('kernel.reset', ['method' => '?reset'])
149150

150151
->set('controller.helper', ControllerHelper::class)
151152
->tag('container.service_subscriber')

src/Symfony/Component/HttpKernel/EventListener/CacheAttributeListener.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,12 @@ public static function getSubscribedEvents(): array
182182
];
183183
}
184184

185+
public function reset(): void
186+
{
187+
$this->lastModified = new \SplObjectStorage();
188+
$this->etags = new \SplObjectStorage();
189+
}
190+
185191
private function getExpressionLanguage(): ExpressionLanguage
186192
{
187193
return $this->expressionLanguage ??= class_exists(ExpressionLanguage::class)

src/Symfony/Component/HttpKernel/EventListener/ProfilerListener.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,14 @@ public function onKernelTerminate(TerminateEvent $event): void
129129
$this->profiler->saveProfile($this->profiles[$request]);
130130
}
131131

132+
$this->reset();
133+
}
134+
135+
public function reset(): void
136+
{
132137
$this->profiles = new \SplObjectStorage();
133138
$this->parents = new \SplObjectStorage();
139+
$this->exception = null;
134140
}
135141

136142
public static function getSubscribedEvents(): array

0 commit comments

Comments
 (0)