bug #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 | #25965
| License | MIT
| Doc PR | -
Commits
-------
926b1bee18
[Debug] Fix bad registration of exception handler, leading to mem leak
This commit is contained in:
commit
0924c001f9
@ -149,9 +149,20 @@ class ErrorHandler
|
|||||||
}
|
}
|
||||||
if (!$replace && $prev) {
|
if (!$replace && $prev) {
|
||||||
restore_error_handler();
|
restore_error_handler();
|
||||||
|
$handlerIsRegistered = is_array($prev) && $handler === $prev[0];
|
||||||
|
} else {
|
||||||
|
$handlerIsRegistered = true;
|
||||||
}
|
}
|
||||||
if (is_array($prev = set_exception_handler(array($handler, 'handleException'))) && $prev[0] === $handler) {
|
if (is_array($prev = set_exception_handler(array($handler, 'handleException'))) && $prev[0] instanceof self) {
|
||||||
restore_exception_handler();
|
restore_exception_handler();
|
||||||
|
if (!$handlerIsRegistered) {
|
||||||
|
$handler = $prev[0];
|
||||||
|
} elseif ($handler !== $prev[0] && $replace) {
|
||||||
|
set_exception_handler(array($handler, 'handleException'));
|
||||||
|
$p = $prev[0]->setExceptionHandler(null);
|
||||||
|
$handler->setExceptionHandler($p);
|
||||||
|
$prev[0]->setExceptionHandler($p);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$handler->setExceptionHandler($prev);
|
$handler->setExceptionHandler($prev);
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ class ErrorHandlerTest extends TestCase
|
|||||||
|
|
||||||
$newHandler = new ErrorHandler();
|
$newHandler = new ErrorHandler();
|
||||||
|
|
||||||
$this->assertSame($newHandler, ErrorHandler::register($newHandler, false));
|
$this->assertSame($handler, ErrorHandler::register($newHandler, false));
|
||||||
$h = set_error_handler('var_dump');
|
$h = set_error_handler('var_dump');
|
||||||
restore_error_handler();
|
restore_error_handler();
|
||||||
$this->assertSame(array($handler, 'handleError'), $h);
|
$this->assertSame(array($handler, 'handleError'), $h);
|
||||||
|
Reference in New Issue
Block a user