Skip to content

Commit 9cacc57

Browse files
committed
Track heap->real_size for USE_TRACKED_ALLOC
real_size is returned by memory_get_usage(true), which previously returned 0. Discovered in Symfony ConsumeMessagesCommandTest::testRunWithMemoryLimit() through nightly. Closes phpGH-18880
1 parent 0a42e6f commit 9cacc57

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Zend/zend_alloc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2256,6 +2256,7 @@ void zend_mm_shutdown(zend_mm_heap *heap, bool full, bool silent)
22562256
heap->custom_heap.std._free = free;
22572257
}
22582258
heap->size = 0;
2259+
heap->real_size = 0;
22592260
}
22602261

22612262
if (full) {
@@ -2799,6 +2800,7 @@ static void *tracked_malloc(size_t size)
27992800
void *ptr = __zend_malloc(size);
28002801
tracked_add(heap, ptr, size);
28012802
heap->size += size;
2803+
heap->real_size = heap->size;
28022804
return ptr;
28032805
}
28042806

@@ -2810,6 +2812,7 @@ static void tracked_free(void *ptr) {
28102812
zend_mm_heap *heap = AG(mm_heap);
28112813
zval *size_zv = tracked_get_size_zv(heap, ptr);
28122814
heap->size -= Z_LVAL_P(size_zv);
2815+
heap->real_size = heap->size;
28132816
zend_hash_del_bucket(heap->tracked_allocs, (Bucket *) size_zv);
28142817
free(ptr);
28152818
}
@@ -2835,6 +2838,7 @@ static void *tracked_realloc(void *ptr, size_t new_size) {
28352838
ptr = __zend_realloc(ptr, new_size);
28362839
tracked_add(heap, ptr, new_size);
28372840
heap->size += new_size - old_size;
2841+
heap->real_size = heap->size;
28382842
return ptr;
28392843
}
28402844

0 commit comments

Comments
 (0)