diff --git a/Zend/tests/bug40770.phpt b/Zend/tests/bug40770.phpt index f37d96d5ff333..c5f7d658c59f1 100644 --- a/Zend/tests/bug40770.phpt +++ b/Zend/tests/bug40770.phpt @@ -19,4 +19,4 @@ for ($i=0; $i<=$mb; $i++) { } ?> --EXPECTF-- -Fatal error: Allowed memory size of 8388608 bytes exhausted%s(tried to allocate %d bytes) in %s on line %d +Fatal error: Allowed memory size of %d bytes exhausted by %d bytes%S. Allocated %d bytes and need to allocate %d bytes to satisfy a reallocation from %d to %d bytes in %s on line %d diff --git a/Zend/tests/bug54268.phpt b/Zend/tests/bug54268.phpt index 3567aaa6ee570..a5986940844bc 100644 --- a/Zend/tests/bug54268.phpt +++ b/Zend/tests/bug54268.phpt @@ -34,4 +34,4 @@ $x = new Test(); Test::$mystatic = new DestructorCreator(); ?> --EXPECTF-- -Fatal error: Allowed memory size of %s bytes exhausted%s(tried to allocate %s bytes) in %s on line %d +Fatal error: Allowed memory size of %d bytes exhausted by %d bytes%S. Allocated %d bytes and need to allocate %d bytes to satisfy a request for %d bytes in %s on line %d diff --git a/Zend/tests/bug55509.phpt b/Zend/tests/bug55509.phpt index 1ae5b04f8a0df..cef6fbf09e2a3 100644 --- a/Zend/tests/bug55509.phpt +++ b/Zend/tests/bug55509.phpt @@ -78,4 +78,4 @@ echo "5\n"; 3 4 -Fatal error: Allowed memory size of %d bytes exhausted%s(tried to allocate %d bytes) in %sbug55509.php on line %d +Fatal error: Allowed memory size of %d bytes exhausted by %d bytes%S. Allocated %d bytes and need to allocate %d bytes in %s on line %d diff --git a/Zend/tests/bug70258.phpt b/Zend/tests/bug70258.phpt index 40915a286ef9e..17048a164c143 100644 --- a/Zend/tests/bug70258.phpt +++ b/Zend/tests/bug70258.phpt @@ -25,4 +25,4 @@ $a = new A; $a->core(); ?> --EXPECTF-- -Fatal error: Allowed memory size of 2097152 bytes exhausted%s(tried to allocate %d bytes) in %s on line %d +Fatal error: Allowed memory size of %d bytes exhausted by %d bytes%S. Allocated %d bytes and need to allocate %d bytes to satisfy a request for %d bytes in %s on line %d diff --git a/Zend/tests/bug76846.phpt b/Zend/tests/bug76846.phpt index cd837bd860973..b19f9b9d25528 100644 --- a/Zend/tests/bug76846.phpt +++ b/Zend/tests/bug76846.phpt @@ -23,4 +23,4 @@ while (true) { ?> --EXPECTF-- -Fatal error: Allowed memory size of %d bytes exhausted%s(tried to allocate %d bytes) in %s on line %d%A +Fatal error: Allowed memory size of %d bytes exhausted by %d bytes%S. Allocated %d bytes and need to allocate %d bytes to satisfy a reallocation from %d to %d bytes in %s on line %d diff --git a/Zend/tests/bug79836_4.phpt b/Zend/tests/bug79836_4.phpt index 2d6b862f42139..33f4fe14edd53 100644 --- a/Zend/tests/bug79836_4.phpt +++ b/Zend/tests/bug79836_4.phpt @@ -15,4 +15,4 @@ $e = new Foo(); $e .= $i; ?> --EXPECTF-- -Fatal error: Allowed memory size of %d bytes exhausted%s(tried to allocate %d bytes) in %s on line %d +Fatal error: Allowed memory size of %d bytes exhausted by %d bytes%S. Allocated %d bytes and need to allocate %d bytes in %s on line %d diff --git a/Zend/tests/fibers/get-return-after-bailout.phpt b/Zend/tests/fibers/get-return-after-bailout.phpt index 04bd464cfab0e..6105d65be8411 100644 --- a/Zend/tests/fibers/get-return-after-bailout.phpt +++ b/Zend/tests/fibers/get-return-after-bailout.phpt @@ -22,7 +22,7 @@ $fiber->start(); ?> --EXPECTF-- -Fatal error: Allowed memory size of %d bytes exhausted%s(tried to allocate %d bytes) %sget-return-after-bailout.php on line %d +Fatal error: Allowed memory size of %d bytes exhausted by %d bytes%S. Allocated %d bytes and need to allocate %d bytes in %s on line %d Fatal error: Uncaught FiberError: Cannot get fiber return value: The fiber exited with a fatal error in %sget-return-after-bailout.php:%d Stack trace: diff --git a/Zend/tests/fibers/out-of-memory-in-fiber.phpt b/Zend/tests/fibers/out-of-memory-in-fiber.phpt index 4d31aa6f76adc..5263e916beca2 100644 --- a/Zend/tests/fibers/out-of-memory-in-fiber.phpt +++ b/Zend/tests/fibers/out-of-memory-in-fiber.phpt @@ -22,4 +22,4 @@ $fiber->start(); ?> --EXPECTF-- -Fatal error: Allowed memory size of %d bytes exhausted%s(tried to allocate %d bytes) in %sout-of-memory-in-fiber.php on line %d +Fatal error: Allowed memory size of %d bytes exhausted by %d bytes%S. Allocated %d bytes and need to allocate %d bytes to satisfy a request for %d bytes in %s on line %d diff --git a/Zend/tests/fibers/out-of-memory-in-nested-fiber.phpt b/Zend/tests/fibers/out-of-memory-in-nested-fiber.phpt index 9e82b893faddb..f8516e3592d51 100644 --- a/Zend/tests/fibers/out-of-memory-in-nested-fiber.phpt +++ b/Zend/tests/fibers/out-of-memory-in-nested-fiber.phpt @@ -26,4 +26,4 @@ $fiber->start(); ?> --EXPECTF-- -Fatal error: Allowed memory size of %d bytes exhausted%s(tried to allocate %d bytes) in %sout-of-memory-in-nested-fiber.php on line %d +Fatal error: Allowed memory size of %d bytes exhausted by %d bytes%S. Allocated %d bytes and need to allocate %d bytes to satisfy a request for %d bytes in %s on line %d diff --git a/Zend/tests/fibers/out-of-memory-in-recursive-fiber.phpt b/Zend/tests/fibers/out-of-memory-in-recursive-fiber.phpt index bf711629229bd..34d30c80a2780 100644 --- a/Zend/tests/fibers/out-of-memory-in-recursive-fiber.phpt +++ b/Zend/tests/fibers/out-of-memory-in-recursive-fiber.phpt @@ -23,4 +23,4 @@ $fiber->start(); ?> --EXPECTF-- -Fatal error: Allowed memory size of %d bytes exhausted%s(tried to allocate %d bytes) in %sout-of-memory-in-recursive-fiber.php on line %d +Fatal error: Allowed memory size of %d bytes exhausted by %d bytes%S. Allocated %d bytes and need to allocate %d bytes to satisfy a request for %d bytes in %s on line %d diff --git a/Zend/tests/gh11189.phpt b/Zend/tests/gh11189.phpt index f1c877f20ee47..c25f317d3fd34 100644 --- a/Zend/tests/gh11189.phpt +++ b/Zend/tests/gh11189.phpt @@ -26,4 +26,4 @@ while (1) { ?> --EXPECTF-- Success -Fatal error: Allowed memory size of %s bytes exhausted%s(tried to allocate %s bytes) in %s on line %d +Fatal error: Allowed memory size of %d bytes exhausted by %d bytes%S. Allocated %d bytes and need to allocate %d bytes in %s on line %d diff --git a/Zend/tests/gh11189_1.phpt b/Zend/tests/gh11189_1.phpt index 53727908e5e2a..8c9a78f61c56d 100644 --- a/Zend/tests/gh11189_1.phpt +++ b/Zend/tests/gh11189_1.phpt @@ -26,4 +26,4 @@ while (1) { ?> --EXPECTF-- Success -Fatal error: Allowed memory size of %s bytes exhausted%s(tried to allocate %s bytes) in %s on line %d +Fatal error: Allowed memory size of %d bytes exhausted by %d bytes%S. Allocated %d bytes and need to allocate %d bytes to satisfy a request for %d bytes in %s on line %d diff --git a/Zend/tests/gh12073.phpt b/Zend/tests/gh12073.phpt index ef115685ce7d4..c4ed3d438d512 100644 --- a/Zend/tests/gh12073.phpt +++ b/Zend/tests/gh12073.phpt @@ -25,4 +25,4 @@ for ($i = 0; $i < 10_000; $i++) { ?> --EXPECTF-- -Fatal error: Allowed memory size of %d bytes exhausted%s(tried to allocate %d bytes) in %s on line %d +Fatal error: Allowed memory size of %d bytes exhausted by %d bytes%S. Allocated %d bytes and need to allocate %d bytes to satisfy a request for %d bytes in %s on line %d diff --git a/Zend/tests/new_oom.phpt b/Zend/tests/new_oom.phpt index 93d1bdf7b691a..5fe8b3d3c8de2 100644 --- a/Zend/tests/new_oom.phpt +++ b/Zend/tests/new_oom.phpt @@ -12,7 +12,7 @@ $php = PHP_BINARY; foreach (get_declared_classes() as $class) { $output = shell_exec("$php --no-php-ini $file $class 2>&1"); - if ($output && preg_match('(^\nFatal error: Allowed memory size of [0-9]+ bytes exhausted[^\r\n]* \(tried to allocate [0-9]+ bytes\) in [^\r\n]+ on line [0-9]+$)', $output) !== 1) { + if ($output && preg_match('(^\nFatal error: Allowed memory size of [0-9]+ bytes exhausted by [0-9]+ bytes[^\r\n]*. Allocated [0-9]+ bytes and need to allocate [0-9]+ bytes to satisfy a request for [0-9]+ bytes in [^\r\n]+ on line [0-9]+$)', $output) !== 1) { echo "Class $class failed\n"; echo $output, "\n"; } diff --git a/Zend/zend_alloc.c b/Zend/zend_alloc.c index 875c736413ee2..82b413200e355 100644 --- a/Zend/zend_alloc.c +++ b/Zend/zend_alloc.c @@ -368,26 +368,17 @@ static ZEND_COLD ZEND_NORETURN void zend_mm_panic(const char *message) abort(); } -static ZEND_COLD ZEND_NORETURN void zend_mm_safe_error(zend_mm_heap *heap, - const char *format, - size_t limit, -#if ZEND_DEBUG - const char *filename, - uint32_t lineno, -#endif - size_t size) +static ZEND_COLD ZEND_NORETURN void zend_mm_safe_error(zend_mm_heap *heap, char* format, ...) { + va_list args; heap->overflow = 1; zend_try { - zend_error_noreturn(E_ERROR, - format, - limit, -#if ZEND_DEBUG - filename, - lineno, -#endif - size); + va_start(args, format); + zend_string *message = zend_vstrpprintf(0, format, args); + zend_error_noreturn(E_ERROR, "%s", ZSTR_VAL(message)); + zend_string_release(message); + va_end(args); } zend_catch { } zend_end_try(); heap->overflow = 0; @@ -1009,11 +1000,26 @@ static void *zend_mm_alloc_pages(zend_mm_heap *heap, uint32_t pages_count ZEND_F if (zend_mm_gc(heap)) { goto get_chunk; } else if (heap->overflow == 0) { -#if ZEND_DEBUG - zend_mm_safe_error(heap, "Allowed memory size of %zu bytes exhausted at %s:%d (tried to allocate %zu bytes)", heap->limit, __zend_filename, __zend_lineno, size); -#else - zend_mm_safe_error(heap, "Allowed memory size of %zu bytes exhausted (tried to allocate %zu bytes)", heap->limit, ZEND_MM_PAGE_SIZE * pages_count); -#endif + zend_mm_safe_error( + heap, + "Allowed memory size of %zu bytes exhausted by %zu bytes" +# if ZEND_DEBUG + " at %s:%d" +# endif + ". Allocated %zu bytes and need to allocate %zu bytes to satisfy a request for %zu bytes", + + heap->limit, (ZEND_MM_CHUNK_SIZE - (heap->limit - heap->real_size)), +# if ZEND_DEBUG + __zend_filename, __zend_lineno, +# endif + heap->real_size, ZEND_MM_CHUNK_SIZE, +# if ZEND_DEBUG + size +# else + ZEND_MM_PAGE_SIZE * pages_count +# endif + ); + return NULL; } } @@ -1028,9 +1034,9 @@ static void *zend_mm_alloc_pages(zend_mm_heap *heap, uint32_t pages_count ZEND_F #if !ZEND_MM_LIMIT zend_mm_safe_error(heap, "Out of memory"); #elif ZEND_DEBUG - zend_mm_safe_error(heap, "Out of memory (allocated %zu bytes) at %s:%d (tried to allocate %zu bytes)", heap->real_size, __zend_filename, __zend_lineno, size); + zend_mm_safe_error(heap, "Out of memory (allocated %zu bytes) at %s:%d (tried to allocate %zu bytes)", heap->real_size, __zend_filename, __zend_lineno, ZEND_MM_CHUNK_SIZE); #else - zend_mm_safe_error(heap, "Out of memory (allocated %zu bytes) (tried to allocate %zu bytes)", heap->real_size, ZEND_MM_PAGE_SIZE * pages_count); + zend_mm_safe_error(heap, "Out of memory (allocated %zu bytes) (tried to allocate %zu bytes)", heap->real_size, ZEND_MM_CHUNK_SIZE); #endif return NULL; } @@ -1535,11 +1541,20 @@ static zend_never_inline void *zend_mm_realloc_huge(zend_mm_heap *heap, void *pt if (zend_mm_gc(heap) && new_size - old_size <= heap->limit - heap->real_size) { /* pass */ } else if (heap->overflow == 0) { -#if ZEND_DEBUG - zend_mm_safe_error(heap, "Allowed memory size of %zu bytes exhausted at %s:%d (tried to allocate %zu bytes)", heap->limit, __zend_filename, __zend_lineno, size); -#else - zend_mm_safe_error(heap, "Allowed memory size of %zu bytes exhausted (tried to allocate %zu bytes)", heap->limit, size); -#endif + zend_mm_safe_error( + heap, + "Allowed memory size of %zu bytes exhausted by %zu bytes" +# if ZEND_DEBUG + " at %s:%d" +# endif + ". Allocated %zu bytes and need to allocate %zu bytes to satisfy a reallocation from %zu to %zu bytes", + + heap->limit, ((new_size - old_size) - (heap->limit - heap->real_size)), +# if ZEND_DEBUG + __zend_filename, __zend_lineno, +# endif + heap->real_size, (new_size - old_size), old_size, new_size + ); return NULL; } } @@ -1827,11 +1842,20 @@ static void *zend_mm_alloc_huge(zend_mm_heap *heap, size_t size ZEND_FILE_LINE_D if (zend_mm_gc(heap) && new_size <= heap->limit - heap->real_size) { /* pass */ } else if (heap->overflow == 0) { -#if ZEND_DEBUG - zend_mm_safe_error(heap, "Allowed memory size of %zu bytes exhausted at %s:%d (tried to allocate %zu bytes)", heap->limit, __zend_filename, __zend_lineno, size); -#else - zend_mm_safe_error(heap, "Allowed memory size of %zu bytes exhausted (tried to allocate %zu bytes)", heap->limit, size); -#endif + zend_mm_safe_error( + heap, + "Allowed memory size of %zu bytes exhausted by %zu bytes" +# if ZEND_DEBUG + " at %s:%d" +# endif + ". Allocated %zu bytes and need to allocate %zu bytes", + + heap->limit, (new_size - (heap->limit - heap->real_size)), +# if ZEND_DEBUG + __zend_filename, __zend_lineno, +# endif + heap->real_size, new_size + ); return NULL; } } @@ -1846,9 +1870,9 @@ static void *zend_mm_alloc_huge(zend_mm_heap *heap, size_t size ZEND_FILE_LINE_D #if !ZEND_MM_LIMIT zend_mm_safe_error(heap, "Out of memory"); #elif ZEND_DEBUG - zend_mm_safe_error(heap, "Out of memory (allocated %zu bytes) at %s:%d (tried to allocate %zu bytes)", heap->real_size, __zend_filename, __zend_lineno, size); + zend_mm_safe_error(heap, "Out of memory (allocated %zu bytes) at %s:%d (tried to allocate %zu bytes)", heap->real_size, __zend_filename, __zend_lineno, new_size); #else - zend_mm_safe_error(heap, "Out of memory (allocated %zu bytes) (tried to allocate %zu bytes)", heap->real_size, size); + zend_mm_safe_error(heap, "Out of memory (allocated %zu bytes) (tried to allocate %zu bytes)", heap->real_size, new_size); #endif return NULL; } @@ -2823,15 +2847,20 @@ static zend_always_inline zval *tracked_get_size_zv(zend_mm_heap *heap, void *pt static zend_always_inline void tracked_check_limit(zend_mm_heap *heap, size_t add_size) { if (add_size > heap->limit - heap->size && !heap->overflow) { -#if ZEND_DEBUG - zend_mm_safe_error(heap, - "Allowed memory size of %zu bytes exhausted at %s:%d (tried to allocate %zu bytes)", - heap->limit, "file", 0, add_size); -#else - zend_mm_safe_error(heap, - "Allowed memory size of %zu bytes exhausted (tried to allocate %zu bytes)", - heap->limit, add_size); -#endif + zend_mm_safe_error( + heap, + "Allowed memory size of %zu bytes exhausted by %zu bytes" +# if ZEND_DEBUG + " at %s:%d" +# endif + ". Allocated %zu bytes and need to allocate %zu bytes", + + heap->limit, (add_size - (heap->limit - heap->real_size)), +# if ZEND_DEBUG + "file", 0, +# endif + heap->real_size, add_size + ); } } diff --git a/ext/oci8/tests/pecl_bug10194.phpt b/ext/oci8/tests/pecl_bug10194.phpt index 5abe77da8d9f2..fe776022d996d 100644 --- a/ext/oci8/tests/pecl_bug10194.phpt +++ b/ext/oci8/tests/pecl_bug10194.phpt @@ -54,4 +54,4 @@ require __DIR__.'/drop_table.inc'; echo "Done\n"; ?> --EXPECTF-- -Fatal error: Allowed memory size of 10485760 bytes exhausted%s(tried to allocate %d bytes) in %s on line %d +Fatal error: Allowed memory size of %d bytes exhausted by %d bytes%S. Allocated %d bytes and need to allocate %d bytes in %s on line %d diff --git a/ext/oci8/tests/pecl_bug10194_blob.phpt b/ext/oci8/tests/pecl_bug10194_blob.phpt index a6a08764f6aae..0d1e1a73b4c20 100644 --- a/ext/oci8/tests/pecl_bug10194_blob.phpt +++ b/ext/oci8/tests/pecl_bug10194_blob.phpt @@ -58,4 +58,4 @@ echo "Done\n"; --EXPECTF-- Before load() -Fatal error: Allowed memory size of %d bytes exhausted%s(tried to allocate %d bytes) in %s on line %d +Fatal error: Allowed memory size of %d bytes exhausted by %d bytes%S. Allocated %d bytes and need to allocate %d bytes in %s on line %d diff --git a/ext/oci8/tests/pecl_bug10194_blob_64.phpt b/ext/oci8/tests/pecl_bug10194_blob_64.phpt index 8893570e20dc8..db5611f8ddb9d 100644 --- a/ext/oci8/tests/pecl_bug10194_blob_64.phpt +++ b/ext/oci8/tests/pecl_bug10194_blob_64.phpt @@ -59,4 +59,4 @@ echo "Done\n"; --EXPECTF-- Before load() -Fatal error: Allowed memory size of %d bytes exhausted%s(tried to allocate %d bytes) in %s on line %d +Fatal error: Allowed memory size of %d bytes exhausted by %d bytes%S. Allocated %d bytes and need to allocate %d bytes in %s on line %d diff --git a/ext/standard/tests/streams/bug61115-1.phpt b/ext/standard/tests/streams/bug61115-1.phpt index 892b0f80e5792..2f5f300b88117 100644 --- a/ext/standard/tests/streams/bug61115-1.phpt +++ b/ext/standard/tests/streams/bug61115-1.phpt @@ -14,4 +14,4 @@ stream_context_get_options($fileResourceTemp); ftruncate($fileResourceTemp, PHP_INT_MAX); ?> --EXPECTF-- -Fatal error: Allowed memory size of %d bytes exhausted%s(tried to allocate %d bytes) in %s on line %d +Fatal error: Allowed memory size of %d bytes exhausted by %d bytes%S. Allocated %d bytes and need to allocate %d bytes in %s on line %d diff --git a/ext/standard/tests/strings/chunk_split_variation3.phpt b/ext/standard/tests/strings/chunk_split_variation3.phpt index 56c524ef02d57..c9e52affb8509 100644 --- a/ext/standard/tests/strings/chunk_split_variation3.phpt +++ b/ext/standard/tests/strings/chunk_split_variation3.phpt @@ -21,4 +21,4 @@ var_dump(chunk_split($body, $chunk_length)); Body generation Using chunk_split() -Fatal error: Allowed memory size of %d bytes exhausted%s(tried to allocate %d bytes) in %s on line %d +Fatal error: Allowed memory size of %d bytes exhausted by %d bytes%S. Allocated %d bytes and need to allocate %d bytes in %s on line %d diff --git a/ext/standard/tests/strings/str_pad_variation1.phpt b/ext/standard/tests/strings/str_pad_variation1.phpt index cb71e61156fcd..4a86e40cd6136 100644 --- a/ext/standard/tests/strings/str_pad_variation1.phpt +++ b/ext/standard/tests/strings/str_pad_variation1.phpt @@ -33,4 +33,4 @@ var_dump( str_pad($input, $php_int_max_pad_length) ); *** Testing str_pad() function: with large value for for 'pad_length' argument *** str_pad(): Argument #2 ($length) must be of type int, float given -Fatal error: Allowed memory size of %d bytes exhausted%s(tried to allocate %d bytes) in %s on line %d +Fatal error: Allowed memory size of %d bytes exhausted by %d bytes%S. Allocated %d bytes and need to allocate %d bytes in %s on line %d diff --git a/ext/standard/tests/strings/wordwrap_memory_limit.phpt b/ext/standard/tests/strings/wordwrap_memory_limit.phpt index 21340153faea1..dbd02d1daa573 100644 --- a/ext/standard/tests/strings/wordwrap_memory_limit.phpt +++ b/ext/standard/tests/strings/wordwrap_memory_limit.phpt @@ -16,4 +16,4 @@ wordwrap($str, 1, $str2); ?> --EXPECTF-- -Fatal error: Allowed memory size of 134217728 bytes exhausted%s(tried to allocate %d bytes) in %s on line %d +Fatal error: Allowed memory size of %d bytes exhausted by %d bytes%S. Allocated %d bytes and need to allocate %d bytes in %s on line %d diff --git a/ext/zend_test/tests/observer_error_01.phpt b/ext/zend_test/tests/observer_error_01.phpt index 971080089c10d..c937dc6ec25e6 100644 --- a/ext/zend_test/tests/observer_error_01.phpt +++ b/ext/zend_test/tests/observer_error_01.phpt @@ -30,7 +30,7 @@ echo 'You should not see this.'; -Fatal error: Allowed memory size of 2097152 bytes exhausted%s(tried to allocate %d bytes) in %s on line %d +Fatal error: Allowed memory size of %d bytes exhausted by %d bytes%S. Allocated %d bytes and need to allocate %d bytes in %s on line %d