[php-src] PR #11763: Fix the attempted allocation size in OOM error messages

From: Date: Sat, 22 Jul 2023 13:03:48 +0000
Subject: [php-src] PR #11763: Fix the attempted allocation size in OOM error messages
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-23137@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/11763 Author: TimWolla The sizes reported in the error messages previously didn't match the sizes that were actually checked against the memory limit. This can result in confusing error reports, because the reported size often tends to be much smaller than the actual chunk allocation size used in accounting. Consider the following example script: <?php $foo = []; while (true) { var_dump(memory_get_usage()); $foo[] = new stdClass(); } Executing the script as sapi/cli/php -dmemory_limit=5145728 oom.php results in: int(3833360) int(3833440) int(3833520) Fatal error: Allowed memory size of 5145728 bytes exhausted at php-src/Zend/zend_objects_API.c:136 (tried to allocate 524320 bytes) in php-src/oom.php on line 5 With each iteration the actual memory usage grows by 80 bytes. The error message reports roughly 512 KiB of additional usage, possibly for an array resizing, but even for those additional 512 KiB the last observed memory usage does not exceed the memory limit of 5145728 Bytes. This is because actually a chunk of 2 MiB is going to be allocated and that is what is checked. The following output was created with this patch applied: int(3833360) int(3833440) int(3833520) Fatal error: Allowed memory size of 5145728 bytes exhausted at php-src/Zend/zend_objects_API.c:136 (tried to allocate 2097152 bytes) in php-src/oom.php on line 5 With the fixed output the attempted allocation clearly exceeds the memory limit. In a further change the error message could possibly be adjusted to also report the current memory usage instead of just the limit + the attempted allocation.

« previous php.git-pulls (#23137) next »