From 5675ebe649352ffa89754defd87019223b88b4e5 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Thu, 9 Dec 2021 15:36:26 +0100 Subject: [PATCH] Fix #81585: cached_chunks are not counted to real_size on shutdown The amount of allocated system memory is kept in `real_size`, including the allocated `cached_chunks`. Thus, we need to keep the proper count at the end of the shutdown. Closes GH-7745. --- NEWS | 2 ++ Zend/zend_alloc.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 767b2978d4f..9207f3cc6d5 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,8 @@ PHP NEWS - Core: . Fixed bug #81656 (GCC-11 silently ignores -R). (Michael Wallner) + . Fixed bug #81585 (cached_chunks are not counted to real_size on shutdown). + (cmb) - Spl: . Fixed bug #75917 (SplFileObject::seek broken with CSV flags). (Aliaksandr diff --git a/Zend/zend_alloc.c b/Zend/zend_alloc.c index 0d3e41776d7..5738c030a58 100644 --- a/Zend/zend_alloc.c +++ b/Zend/zend_alloc.c @@ -2303,10 +2303,10 @@ void zend_mm_shutdown(zend_mm_heap *heap, bool full, bool silent) #endif memset(heap->free_slot, 0, sizeof(heap->free_slot)); #if ZEND_MM_STAT || ZEND_MM_LIMIT - heap->real_size = ZEND_MM_CHUNK_SIZE; + heap->real_size = (heap->cached_chunks_count + 1) * ZEND_MM_CHUNK_SIZE; #endif #if ZEND_MM_STAT - heap->real_peak = ZEND_MM_CHUNK_SIZE; + heap->real_peak = (heap->cached_chunks_count + 1) * ZEND_MM_CHUNK_SIZE; #endif heap->chunks_count = 1; heap->peak_chunks_count = 1;