Skip to content

Commit ded69ee

Browse files
committed
Make zval_ptr_dtor / _zval_dtor_func more robust
In particular, allow arrays with refcount>1, like we already allow for all other types. _zval_dtor_func is now the same as _zval_dtor_func_for_ptr with an extra refcount decrement check at the start. At this point we might as well drop it...
1 parent 304e5ae commit ded69ee

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

Zend/zend_variables.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,20 @@
3030

3131
ZEND_API void ZEND_FASTCALL _zval_dtor_func(zend_refcounted *p ZEND_FILE_LINE_DC)
3232
{
33+
if (--GC_REFCOUNT(p)) {
34+
return;
35+
}
36+
3337
switch (GC_TYPE(p)) {
3438
case IS_STRING:
3539
case IS_CONSTANT: {
3640
zend_string *str = (zend_string*)p;
3741
CHECK_ZVAL_STRING_REL(str);
38-
zend_string_release(str);
42+
zend_string_free(str);
3943
break;
4044
}
4145
case IS_ARRAY: {
4246
zend_array *arr = (zend_array*)p;
43-
ZEND_ASSERT(GC_REFCOUNT(arr) <= 1);
4447
zend_array_destroy(arr);
4548
break;
4649
}
@@ -54,25 +57,21 @@ ZEND_API void ZEND_FASTCALL _zval_dtor_func(zend_refcounted *p ZEND_FILE_LINE_DC
5457
case IS_OBJECT: {
5558
zend_object *obj = (zend_object*)p;
5659

57-
OBJ_RELEASE(obj);
60+
zend_objects_store_del(obj);
5861
break;
5962
}
6063
case IS_RESOURCE: {
6164
zend_resource *res = (zend_resource*)p;
6265

63-
if (--GC_REFCOUNT(res) == 0) {
64-
/* destroy resource */
65-
zend_list_free(res);
66-
}
66+
/* destroy resource */
67+
zend_list_free(res);
6768
break;
6869
}
6970
case IS_REFERENCE: {
7071
zend_reference *ref = (zend_reference*)p;
71-
if (--GC_REFCOUNT(ref) == 0) {
7272

73-
i_zval_ptr_dtor(&ref->val ZEND_FILE_LINE_RELAY_CC);
74-
efree_size(ref, sizeof(zend_reference));
75-
}
73+
i_zval_ptr_dtor(&ref->val ZEND_FILE_LINE_RELAY_CC);
74+
efree_size(ref, sizeof(zend_reference));
7675
break;
7776
}
7877
default:

0 commit comments

Comments
 (0)