Skip to content

Commit 51c5a97

Browse files
committed
Fix
1 parent d434eb7 commit 51c5a97

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

Zend/zend_alloc.c

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,10 @@ static size_t _real_page_size = ZEND_MM_PAGE_SIZE;
174174
#ifdef __SANITIZE_ADDRESS__
175175
# include <sanitizer/asan_interface.h>
176176

177-
#if 0
177+
#if 1
178178

179179
#define ZEND_MM_POISON_DEBUG(_type, _ptr, _size) do { \
180-
fprintf(stderr, "%s %p - %p in %d\n", (_type), (_ptr), ((size_t)_ptr)+((size_t)_size), __LINE__); \
180+
fprintf(stderr, "%s %p - %p in %d\n", (_type), (_ptr), (void*) (((size_t)_ptr)+((size_t)_size)), __LINE__); \
181181
fflush(stderr); \
182182
} while (0);
183183

@@ -973,6 +973,8 @@ static void zend_mm_change_huge_block_size(zend_mm_heap *heap, void *ptr, size_t
973973
/* Large Runs */
974974
/**************/
975975

976+
static size_t _zend_mm_gc(zend_mm_heap *heap);
977+
976978
#if ZEND_DEBUG
977979
static void *zend_mm_alloc_pages(zend_mm_heap *heap, uint32_t pages_count, size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
978980
#else
@@ -1110,7 +1112,7 @@ static void *zend_mm_alloc_pages(zend_mm_heap *heap, uint32_t pages_count ZEND_F
11101112
} else {
11111113
#if ZEND_MM_LIMIT
11121114
if (UNEXPECTED(ZEND_MM_CHUNK_SIZE > heap->limit - heap->real_size)) {
1113-
if (zend_mm_gc(heap)) {
1115+
if (_zend_mm_gc(heap)) {
11141116
goto get_chunk;
11151117
} else if (heap->overflow == 0) {
11161118
#if ZEND_DEBUG
@@ -1127,7 +1129,7 @@ static void *zend_mm_alloc_pages(zend_mm_heap *heap, uint32_t pages_count ZEND_F
11271129
chunk = (zend_mm_chunk*)zend_mm_chunk_alloc(heap, ZEND_MM_CHUNK_SIZE, ZEND_MM_CHUNK_SIZE);
11281130
if (UNEXPECTED(chunk == NULL)) {
11291131
/* insufficient memory */
1130-
if (zend_mm_gc(heap) &&
1132+
if (_zend_mm_gc(heap) &&
11311133
(chunk = (zend_mm_chunk*)zend_mm_chunk_alloc(heap, ZEND_MM_CHUNK_SIZE, ZEND_MM_CHUNK_SIZE)) != NULL) {
11321134
/* pass */
11331135
} else {
@@ -1772,7 +1774,7 @@ static zend_never_inline void *zend_mm_realloc_huge(zend_mm_heap *heap, void *pt
17721774
} else /* if (new_size > old_size) */ {
17731775
#if ZEND_MM_LIMIT
17741776
if (UNEXPECTED(new_size - old_size > heap->limit - heap->real_size)) {
1775-
if (zend_mm_gc(heap) && new_size - old_size <= heap->limit - heap->real_size) {
1777+
if (_zend_mm_gc(heap) && new_size - old_size <= heap->limit - heap->real_size) {
17761778
/* pass */
17771779
} else if (heap->overflow == 0) {
17781780
#if ZEND_DEBUG
@@ -2092,7 +2094,7 @@ static void *zend_mm_alloc_huge(zend_mm_heap *heap, size_t size ZEND_FILE_LINE_D
20922094

20932095
#if ZEND_MM_LIMIT
20942096
if (UNEXPECTED(new_size > heap->limit - heap->real_size)) {
2095-
if (zend_mm_gc(heap) && new_size <= heap->limit - heap->real_size) {
2097+
if (_zend_mm_gc(heap) && new_size <= heap->limit - heap->real_size) {
20962098
/* pass */
20972099
} else if (heap->overflow == 0) {
20982100
#if ZEND_DEBUG
@@ -2107,7 +2109,7 @@ static void *zend_mm_alloc_huge(zend_mm_heap *heap, size_t size ZEND_FILE_LINE_D
21072109
ptr = zend_mm_chunk_alloc(heap, new_size, ZEND_MM_CHUNK_SIZE);
21082110
if (UNEXPECTED(ptr == NULL)) {
21092111
/* insufficient memory */
2110-
if (zend_mm_gc(heap) &&
2112+
if (_zend_mm_gc(heap) &&
21112113
(ptr = zend_mm_chunk_alloc(heap, new_size, ZEND_MM_CHUNK_SIZE)) != NULL) {
21122114
/* pass */
21132115
} else {
@@ -2231,7 +2233,7 @@ static zend_mm_heap *zend_mm_init(void)
22312233
return heap;
22322234
}
22332235

2234-
ZEND_API size_t zend_mm_gc(zend_mm_heap *heap)
2236+
static size_t _zend_mm_gc(zend_mm_heap *heap)
22352237
{
22362238
zend_mm_free_slot *p, *q;
22372239
zend_mm_chunk *chunk;
@@ -2242,7 +2244,6 @@ ZEND_API size_t zend_mm_gc(zend_mm_heap *heap)
22422244
bool has_free_pages;
22432245
size_t collected = 0;
22442246

2245-
ZEND_MM_UNPOISON_HEAP(heap);
22462247
#if ZEND_MM_CUSTOM
22472248
if (heap->use_custom_heap) {
22482249
size_t (*gc)(void) = heap->custom_heap._gc;
@@ -2341,6 +2342,7 @@ ZEND_API size_t zend_mm_gc(zend_mm_heap *heap)
23412342
if (ZEND_MM_SRUN_FREE_COUNTER(info) == bin_elements[bin_num]) {
23422343
/* all elements are free */
23432344
zend_mm_free_pages_ex(heap, chunk, i, pages_count, 0);
2345+
ZEND_MM_UNPOISON_CHUNK_HDR(chunk);
23442346
collected += pages_count;
23452347
} else {
23462348
/* reset counter */
@@ -2368,11 +2370,18 @@ ZEND_API size_t zend_mm_gc(zend_mm_heap *heap)
23682370
}
23692371
} while (chunk != heap->main_chunk);
23702372
ZEND_MM_POISON_CHUNK_HDR(chunk, heap);
2371-
ZEND_MM_POISON_HEAP(heap);
23722373

23732374
return collected * ZEND_MM_PAGE_SIZE;
23742375
}
23752376

2377+
ZEND_API size_t zend_mm_gc(zend_mm_heap *heap)
2378+
{
2379+
ZEND_MM_UNPOISON_HEAP(heap);
2380+
size_t ret = _zend_mm_gc(heap);
2381+
ZEND_MM_POISON_HEAP(heap);
2382+
return ret;
2383+
}
2384+
23762385
#if ZEND_DEBUG
23772386
/******************/
23782387
/* Leak detection */
@@ -3428,7 +3437,7 @@ static size_t poison_gc(void)
34283437
zend_mm_get_custom_handlers_ex(heap, &_malloc, &_free, &_realloc, &_gc, &_shutdown);
34293438
zend_mm_set_custom_handlers_ex(heap, NULL, NULL, NULL, NULL, NULL);
34303439

3431-
size_t collected = zend_mm_gc(heap);
3440+
size_t collected = _zend_mm_gc(heap);
34323441

34333442
zend_mm_set_custom_handlers_ex(heap, _malloc, _free, _realloc, _gc, _shutdown);
34343443

0 commit comments

Comments
 (0)