Skip to content

Commit d9de798

Browse files
committed
Fixes
1 parent e31c4ac commit d9de798

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Zend/zend_alloc.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3510,6 +3510,7 @@ static void tracked_free_all(zend_mm_heap *heap) {
35103510
static void* poison_malloc(size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
35113511
{
35123512
zend_mm_heap *heap = AG(mm_heap);
3513+
ZEND_MM_UNPOISON_HEAP(heap);
35133514

35143515
if (SIZE_MAX - heap->debug.padding * 2 < size) {
35153516
zend_mm_panic("Integer overflow in memory allocation");
@@ -3529,12 +3530,14 @@ static void* poison_malloc(size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
35293530
ZEND_MM_UNPOISON(ptr, size);
35303531
}
35313532

3533+
ZEND_MM_POISON_HEAP(heap);
35323534
return ptr;
35333535
}
35343536

35353537
static void poison_free(void *ptr ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
35363538
{
35373539
zend_mm_heap *heap = AG(mm_heap);
3540+
ZEND_MM_UNPOISON_HEAP(heap);
35383541

35393542
if (EXPECTED(ptr)) {
35403543
/* zend_mm_shutdown() will try to free the heap when custom handlers
@@ -3555,6 +3558,7 @@ static void poison_free(void *ptr ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
35553558
}
35563559

35573560
zend_mm_free_heap(heap, ptr ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
3561+
ZEND_MM_POISON_HEAP(heap);
35583562
}
35593563

35603564
static void* poison_realloc(void *ptr, size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
@@ -3563,6 +3567,7 @@ static void* poison_realloc(void *ptr, size_t size ZEND_FILE_LINE_DC ZEND_FILE_L
35633567

35643568
void *new = poison_malloc(size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
35653569

3570+
ZEND_MM_UNPOISON_HEAP(heap);
35663571
if (ptr) {
35673572
/* Determine the size of the old allocation from the unpadded pointer. */
35683573
size_t oldsize = zend_mm_size(heap, (char*)ptr - heap->debug.padding ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
@@ -3578,13 +3583,15 @@ static void* poison_realloc(void *ptr, size_t size ZEND_FILE_LINE_DC ZEND_FILE_L
35783583
memcpy(new, ptr, MIN(oldsize, size));
35793584
poison_free(ptr ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
35803585
}
3586+
ZEND_MM_POISON_HEAP(heap);
35813587

35823588
return new;
35833589
}
35843590

35853591
static size_t poison_gc(void)
35863592
{
35873593
zend_mm_heap *heap = AG(mm_heap);
3594+
ZEND_MM_UNPOISON_HEAP(heap);
35883595

35893596
void* (*_malloc)(size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
35903597
void (*_free)(void* ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
@@ -3598,7 +3605,8 @@ static size_t poison_gc(void)
35983605
size_t collected = _zend_mm_gc(heap);
35993606

36003607
_zend_mm_set_custom_handlers_ex(heap, _malloc, _free, _realloc, _gc, _shutdown);
3601-
3608+
3609+
ZEND_MM_POISON_HEAP(heap);
36023610
return collected;
36033611
}
36043612

0 commit comments

Comments
 (0)