[wp-trac] [WordPress Trac] #57876: class WP_Fatal_Error_Handler can not handle memory limit errors
WordPress Trac
noreply at wordpress.org
Mon Mar 6 21:38:44 UTC 2023
#57876: class WP_Fatal_Error_Handler can not handle memory limit errors
-------------------------+-----------------------------
Reporter: amisiewicz | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: trunk
Severity: minor | Keywords: dev-feedback
Focuses: performance |
-------------------------+-----------------------------
I found a potential issue with the following code:
{{{#!php
<?php
register_shutdown_function( array( $handler, 'handle' ) );
}}}
In the handle function, one of the first actions taken is:
{{{#!php
<?php
$error = $this->detect_error();
}}}
I believe this code may not execute properly if a PHP memory limit error
has already occurred.
For example, in the Monolog library's ErrorHandler.php file, the
handleFatalError function is registered as a shutdown function with the
following code:
{{{#!php
<?php
register_shutdown_function([$this, 'handleFatalError']);
$this->reservedMemory = str_repeat(' ', 1024 * $reservedMemorySize);
}}}
Then, in the handleFatalError function, the first action taken is to free
up the reserved memory:
{{{#!php
<?php
$this->reservedMemory = '';
$lastError = error_get_last();
}}}
Therefore, it should be safe to assign $lastError in this context.
Please note that I have not yet conducted any tests to confirm whether
this is a potential bug or whether the code can be enhanced. However, I
wanted to report this issue to ensure that it is not overlooked and will
continue to investigate further. If I find any additional information or
evidence, I will update this report accordingly.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/57876>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list