8000 bug #25971 [Debug] Fix bad registration of exception handler, leading… · sroze/symfony@0924c00 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0924c00

Browse files
committed
bug symfony#25971 [Debug] Fix bad registration of exception handler, leading to mem leak (nicolas-grekas)
This PR was merged into the 2.7 branch. Discussion ---------- [Debug] Fix bad registration of exception handler, leading to mem leak | Q | A | ------------- | --- | Branch? | 27 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#25965 | License | MIT | Doc PR | - Commits ------- 926b1be [Debug] Fix bad registration of exception handler, leading to mem leak
2 parents ceb4e73 + 926b1be commit 0924c00

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/Symfony/Component/Debug/ErrorHandler.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,20 @@ public static function register($handler = null, $replace = true)
149149
}
150150
if (!$replace && $prev) {
151151
restore_error_handler();
152+
$handlerIsRegistered = is_array($prev) && $handler === $prev[0];
153+
} else {
154+
$handlerIsRegistered = true;
152155
}
153-
if (is_array($prev = set_exception_handler(array($handler, 'handleException'))) && $prev[0] === $handler) {
156+
if (is_array($prev = set_exception_handler(array($handler, 'handleException'))) && $prev[0] instanceof self) {
154157
restore_exception_handler();
158+
if (!$handlerIsRegistered) {
159+
$handler = $prev[0];
160+
} elseif ($handler !== $prev[0] && $replace) {
161+
set_exception_handler(array($handler, 'handleException'));
162+
$p = $prev[0]->setExceptionHandler(null);
163+
$handler->setExceptionHandler($p);
164+
$prev[0]->setExceptionHandler($p);
165+
}
155166
} else {
156167
$handler->setExceptionHandler($prev);
157168
}

src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function testRegister()
3434

3535
$newHandler = new ErrorHandler();
3636

37-
$this->assertSame($newHandler, ErrorHandler::register($newHandler, false));
37+
$this->assertSame($handler, ErrorHandler::register($newHandler, false));
3838
$h = set_error_handler('var_dump');
3939
restore_error_handler();
4040
$this->assertSame(array($handler, 'handleError'), $h);

0 commit comments

Comments
 (0)
0