Skip to content

Commit 7bd2b9d

Browse files
committed
Generalize delref assertion
The refcount should never become negative, not just during GC.
1 parent 76fecb3 commit 7bd2b9d

File tree

2 files changed

+1
-5
lines changed

2 files changed

+1
-5
lines changed

Zend/zend_gc.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,6 @@ static void gc_mark_grey(zend_refcounted *ref, gc_stack *stack)
833833
while (zv != end) {
834834
if (Z_REFCOUNTED_P(zv)) {
835835
ref = Z_COUNTED_P(zv);
836-
ZEND_ASSERT(GC_REFCOUNT(ref) > 0);
837836
GC_DELREF(ref);
838837
if (!GC_REF_CHECK_COLOR(ref, GC_GREY)) {
839838
GC_REF_SET_COLOR(ref, GC_GREY);
@@ -844,7 +843,6 @@ static void gc_mark_grey(zend_refcounted *ref, gc_stack *stack)
844843
}
845844
if (EXPECTED(!ht)) {
846845
ref = Z_COUNTED_P(zv);
847-
ZEND_ASSERT(GC_REFCOUNT(ref) > 0);
848846
GC_DELREF(ref);
849847
if (!GC_REF_CHECK_COLOR(ref, GC_GREY)) {
850848
GC_REF_SET_COLOR(ref, GC_GREY);
@@ -865,7 +863,6 @@ static void gc_mark_grey(zend_refcounted *ref, gc_stack *stack)
865863
} else if (GC_TYPE(ref) == IS_REFERENCE) {
866864
if (Z_REFCOUNTED(((zend_reference*)ref)->val)) {
867865
ref = Z_COUNTED(((zend_reference*)ref)->val);
868-
ZEND_ASSERT(GC_REFCOUNT(ref) > 0);
869866
GC_DELREF(ref);
870867
if (!GC_REF_CHECK_COLOR(ref, GC_GREY)) {
871868
GC_REF_SET_COLOR(ref, GC_GREY);
@@ -898,7 +895,6 @@ static void gc_mark_grey(zend_refcounted *ref, gc_stack *stack)
898895
}
899896
if (Z_REFCOUNTED_P(zv)) {
900897
ref = Z_COUNTED_P(zv);
901-
ZEND_ASSERT(GC_REFCOUNT(ref) > 0);
902898
GC_DELREF(ref);
903899
if (!GC_REF_CHECK_COLOR(ref, GC_GREY)) {
904900
GC_REF_SET_COLOR(ref, GC_GREY);
@@ -912,7 +908,6 @@ static void gc_mark_grey(zend_refcounted *ref, gc_stack *stack)
912908
zv = Z_INDIRECT_P(zv);
913909
}
914910
ref = Z_COUNTED_P(zv);
915-
ZEND_ASSERT(GC_REFCOUNT(ref) > 0);
916911
GC_DELREF(ref);
917912
if (!GC_REF_CHECK_COLOR(ref, GC_GREY)) {
918913
GC_REF_SET_COLOR(ref, GC_GREY);

Zend/zend_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,7 @@ static zend_always_inline uint32_t zend_gc_addref(zend_refcounted_h *p) {
10321032
}
10331033

10341034
static zend_always_inline uint32_t zend_gc_delref(zend_refcounted_h *p) {
1035+
ZEND_ASSERT(p->refcount > 0);
10351036
ZEND_RC_MOD_CHECK(p);
10361037
return --(p->refcount);
10371038
}

0 commit comments

Comments
 (0)