Skip to content

Commit 2e2cd65

Browse files
committed
Added asserts to catch GC errors when refcount goes below zero.
1 parent 796efd8 commit 2e2cd65

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

Zend/zend_gc.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,13 +507,15 @@ static void gc_mark_grey(zend_refcounted *ref)
507507
while (zv != end) {
508508
if (Z_REFCOUNTED_P(zv)) {
509509
ref = Z_COUNTED_P(zv);
510+
ZEND_ASSERT(GC_REFCOUNT(ref) > 0);
510511
GC_REFCOUNT(ref)--;
511512
gc_mark_grey(ref);
512513
}
513514
zv++;
514515
}
515516
if (EXPECTED(!ht)) {
516517
ref = Z_COUNTED_P(zv);
518+
ZEND_ASSERT(GC_REFCOUNT(ref) > 0);
517519
GC_REFCOUNT(ref)--;
518520
goto tail_call;
519521
}
@@ -530,6 +532,7 @@ static void gc_mark_grey(zend_refcounted *ref)
530532
} else if (GC_TYPE(ref) == IS_REFERENCE) {
531533
if (Z_REFCOUNTED(((zend_reference*)ref)->val)) {
532534
ref = Z_COUNTED(((zend_reference*)ref)->val);
535+
ZEND_ASSERT(GC_REFCOUNT(ref) > 0);
533536
GC_REFCOUNT(ref)--;
534537
goto tail_call;
535538
}
@@ -559,6 +562,7 @@ static void gc_mark_grey(zend_refcounted *ref)
559562
}
560563
if (Z_REFCOUNTED_P(zv)) {
561564
ref = Z_COUNTED_P(zv);
565+
ZEND_ASSERT(GC_REFCOUNT(ref) > 0);
562566
GC_REFCOUNT(ref)--;
563567
gc_mark_grey(ref);
564568
}
@@ -569,6 +573,7 @@ static void gc_mark_grey(zend_refcounted *ref)
569573
zv = Z_INDIRECT_P(zv);
570574
}
571575
ref = Z_COUNTED_P(zv);
576+
ZEND_ASSERT(GC_REFCOUNT(ref) > 0);
572577
GC_REFCOUNT(ref)--;
573578
goto tail_call;
574579
}

0 commit comments

Comments
 (0)