@@ -2430,7 +2430,9 @@ ZEND_API void zend_mm_shutdown(zend_mm_heap *heap, bool full, bool silent)
24302430 /* Make sure the heap free below does not use tracked_free(). */
24312431 heap -> custom_heap ._free = __zend_free ;
24322432 }
2433+ #if ZEND_MM_STAT
24332434 heap -> size = 0 ;
2435+ #endif
24342436 }
24352437
24362438 void (* shutdown )(bool , bool ) = heap -> custom_heap ._shutdown ;
@@ -2969,6 +2971,7 @@ static zend_always_inline zval *tracked_get_size_zv(zend_mm_heap *heap, void *pt
29692971}
29702972
29712973static zend_always_inline void tracked_check_limit (zend_mm_heap * heap , size_t add_size ) {
2974+ #if ZEND_MM_STAT
29722975 if (add_size > heap -> limit - heap -> size && !heap -> overflow ) {
29732976#if ZEND_DEBUG
29742977 zend_mm_safe_error (heap ,
@@ -2980,6 +2983,7 @@ static zend_always_inline void tracked_check_limit(zend_mm_heap *heap, size_t ad
29802983 heap -> limit , add_size );
29812984#endif
29822985 }
2986+ #endif
29832987}
29842988
29852989static void * tracked_malloc (size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC )
@@ -2993,7 +2997,9 @@ static void *tracked_malloc(size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC
29932997 }
29942998
29952999 tracked_add (heap , ptr , size );
3000+ #if ZEND_MM_STAT
29963001 heap -> size += size ;
3002+ #endif
29973003 return ptr ;
29983004}
29993005
@@ -3004,7 +3010,9 @@ static void tracked_free(void *ptr ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC) {
30043010
30053011 zend_mm_heap * heap = AG (mm_heap );
30063012 zval * size_zv = tracked_get_size_zv (heap , ptr );
3013+ #if ZEND_MM_STAT
30073014 heap -> size -= Z_LVAL_P (size_zv );
3015+ #endif
30083016 zend_hash_del_bucket (heap -> tracked_allocs , (Bucket * ) size_zv );
30093017 free (ptr );
30103018}
@@ -3029,7 +3037,9 @@ static void *tracked_realloc(void *ptr, size_t new_size ZEND_FILE_LINE_DC ZEND_F
30293037
30303038 ptr = __zend_realloc (ptr , new_size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC );
30313039 tracked_add (heap , ptr , new_size );
3040+ #if ZEND_MM_STAT
30323041 heap -> size += new_size - old_size ;
3042+ #endif
30333043 return ptr ;
30343044}
30353045
0 commit comments