@@ -368,26 +368,17 @@ static ZEND_COLD ZEND_NORETURN void zend_mm_panic(const char *message)
368
368
abort ();
369
369
}
370
370
371
- static ZEND_COLD ZEND_NORETURN void zend_mm_safe_error (zend_mm_heap * heap ,
372
- const char * format ,
373
- size_t limit ,
374
- #if ZEND_DEBUG
375
- const char * filename ,
376
- uint32_t lineno ,
377
- #endif
378
- size_t size )
371
+ static ZEND_COLD ZEND_NORETURN void zend_mm_safe_error (zend_mm_heap * heap , char * format , ...)
379
372
{
373
+ va_list args ;
380
374
381
375
heap -> overflow = 1 ;
382
376
zend_try {
383
- zend_error_noreturn (E_ERROR ,
384
- format ,
385
- limit ,
386
- #if ZEND_DEBUG
387
- filename ,
388
- lineno ,
389
- #endif
390
- size );
377
+ va_start (args , format );
378
+ zend_string * message = zend_vstrpprintf (0 , format , args );
379
+ zend_error_noreturn (E_ERROR , "%s" , ZSTR_VAL (message ));
380
+ zend_string_release (message );
381
+ va_end (args );
391
382
} zend_catch {
392
383
} zend_end_try ();
393
384
heap -> overflow = 0 ;
@@ -1009,11 +1000,21 @@ static void *zend_mm_alloc_pages(zend_mm_heap *heap, uint32_t pages_count ZEND_F
1009
1000
if (zend_mm_gc (heap )) {
1010
1001
goto get_chunk ;
1011
1002
} else if (heap -> overflow == 0 ) {
1012
- #if ZEND_DEBUG
1013
- 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 , ZEND_MM_CHUNK_SIZE );
1014
- #else
1015
- zend_mm_safe_error (heap , "Allowed memory size of %zu bytes exhausted (tried to allocate %zu bytes)" , heap -> limit , ZEND_MM_CHUNK_SIZE );
1016
- #endif
1003
+ zend_mm_safe_error (
1004
+ heap ,
1005
+ "Allowed memory size of %zu bytes exhausted by %zu bytes"
1006
+ # if ZEND_DEBUG
1007
+ " at %s:%d"
1008
+ # endif
1009
+ ". Allocated %zu bytes and need to allocate %zu bytes to satisfy a request for %zu bytes" ,
1010
+
1011
+ heap -> limit , (ZEND_MM_CHUNK_SIZE - (heap -> limit - heap -> real_size )),
1012
+ # if ZEND_DEBUG
1013
+ __zend_filename , __zend_lineno ,
1014
+ # endif
1015
+ heap -> real_size , ZEND_MM_CHUNK_SIZE , (ZEND_DEBUG ? size : ZEND_MM_PAGE_SIZE * pages_count )
1016
+ );
1017
+
1017
1018
return NULL ;
1018
1019
}
1019
1020
}
@@ -1535,11 +1536,20 @@ static zend_never_inline void *zend_mm_realloc_huge(zend_mm_heap *heap, void *pt
1535
1536
if (zend_mm_gc (heap ) && new_size - old_size <= heap -> limit - heap -> real_size ) {
1536
1537
/* pass */
1537
1538
} else if (heap -> overflow == 0 ) {
1538
- #if ZEND_DEBUG
1539
- 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 , (new_size - old_size ));
1540
- #else
1541
- zend_mm_safe_error (heap , "Allowed memory size of %zu bytes exhausted (tried to allocate %zu bytes)" , heap -> limit , (new_size - old_size ));
1542
- #endif
1539
+ zend_mm_safe_error (
1540
+ heap ,
1541
+ "Allowed memory size of %zu bytes exhausted by %zu bytes"
1542
+ # if ZEND_DEBUG
1543
+ " at %s:%d"
1544
+ # endif
1545
+ ". Allocated %zu bytes and need to allocate %zu bytes to satisfy a reallocation from %zu to %zu bytes" ,
1546
+
1547
+ heap -> limit , ((new_size - old_size ) - (heap -> limit - heap -> real_size )),
1548
+ # if ZEND_DEBUG
1549
+ __zend_filename , __zend_lineno ,
1550
+ # endif
1551
+ heap -> real_size , (new_size - old_size ), old_size , new_size
1552
+ );
1543
1553
return NULL ;
1544
1554
}
1545
1555
}
@@ -1827,11 +1837,20 @@ static void *zend_mm_alloc_huge(zend_mm_heap *heap, size_t size ZEND_FILE_LINE_D
1827
1837
if (zend_mm_gc (heap ) && new_size <= heap -> limit - heap -> real_size ) {
1828
1838
/* pass */
1829
1839
} else if (heap -> overflow == 0 ) {
1830
- #if ZEND_DEBUG
1831
- 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 , new_size );
1832
- #else
1833
- zend_mm_safe_error (heap , "Allowed memory size of %zu bytes exhausted (tried to allocate %zu bytes)" , heap -> limit , new_size );
1834
- #endif
1840
+ zend_mm_safe_error (
1841
+ heap ,
1842
+ "Allowed memory size of %zu bytes exhausted by %zu bytes"
1843
+ # if ZEND_DEBUG
1844
+ " at %s:%d"
1845
+ # endif
1846
+ ". Allocated %zu bytes and need to allocate %zu bytes" ,
1847
+
1848
+ heap -> limit , (new_size - (heap -> limit - heap -> real_size )),
1849
+ # if ZEND_DEBUG
1850
+ __zend_filename , __zend_lineno ,
1851
+ # endif
1852
+ heap -> real_size , new_size
1853
+ );
1835
1854
return NULL ;
1836
1855
}
1837
1856
}
@@ -2823,15 +2842,20 @@ static zend_always_inline zval *tracked_get_size_zv(zend_mm_heap *heap, void *pt
2823
2842
2824
2843
static zend_always_inline void tracked_check_limit (zend_mm_heap * heap , size_t add_size ) {
2825
2844
if (add_size > heap -> limit - heap -> size && !heap -> overflow ) {
2826
- #if ZEND_DEBUG
2827
- zend_mm_safe_error (heap ,
2828
- "Allowed memory size of %zu bytes exhausted at %s:%d (tried to allocate %zu bytes)" ,
2829
- heap -> limit , "file" , 0 , add_size );
2830
- #else
2831
- zend_mm_safe_error (heap ,
2832
- "Allowed memory size of %zu bytes exhausted (tried to allocate %zu bytes)" ,
2833
- heap -> limit , add_size );
2834
- #endif
2845
+ zend_mm_safe_error (
2846
+ heap ,
2847
+ "Allowed memory size of %zu bytes exhausted by %zu bytes"
2848
+ # if ZEND_DEBUG
2849
+ " at %s:%d"
2850
+ # endif
2851
+ ". Allocated %zu bytes and need to allocate %zu bytes" ,
2852
+
2853
+ heap -> limit , (add_size - (heap -> limit - heap -> real_size )),
2854
+ # if ZEND_DEBUG
2855
+ "file" , 0 ,
2856
+ # endif
2857
+ heap -> real_size , add_size
2858
+ );
2835
2859
}
2836
2860
}
2837
2861
0 commit comments