Skip to content

zend_alloc: Fix compile with ZEND_MM_STAT=0 #18811

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Zend/zend_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2274,7 +2274,9 @@ void zend_mm_shutdown(zend_mm_heap *heap, bool full, bool silent)
/* Make sure the heap free below does not use tracked_free(). */
heap->custom_heap.std._free = free;
}
#if ZEND_MM_STAT
heap->size = 0;
#endif
}

if (full) {
Expand Down Expand Up @@ -2820,6 +2822,7 @@ 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 ZEND_MM_STAT
if (add_size > heap->limit - heap->size && !heap->overflow) {
#if ZEND_DEBUG
zend_mm_safe_error(heap,
Expand All @@ -2831,6 +2834,7 @@ static zend_always_inline void tracked_check_limit(zend_mm_heap *heap, size_t ad
heap->limit, add_size);
#endif
}
#endif
}

static void *tracked_malloc(size_t size)
Expand All @@ -2844,7 +2848,9 @@ static void *tracked_malloc(size_t size)
}

tracked_add(heap, ptr, size);
#if ZEND_MM_STAT
heap->size += size;
#endif
return ptr;
}

Expand All @@ -2855,7 +2861,9 @@ static void tracked_free(void *ptr) {

zend_mm_heap *heap = AG(mm_heap);
zval *size_zv = tracked_get_size_zv(heap, ptr);
#if ZEND_MM_STAT
heap->size -= Z_LVAL_P(size_zv);
#endif
zend_hash_del_bucket(heap->tracked_allocs, (Bucket *) size_zv);
free(ptr);
}
Expand All @@ -2880,7 +2888,9 @@ static void *tracked_realloc(void *ptr, size_t new_size) {

ptr = __zend_realloc(ptr, new_size);
tracked_add(heap, ptr, new_size);
#if ZEND_MM_STAT
heap->size += new_size - old_size;
#endif
return ptr;
}

Expand Down
Loading