Skip to content

Commit 24acb4f

Browse files
dstogoviluuu1994
authored andcommitted
Delay destructor for zend_std_write_property
1 parent b39107c commit 24acb4f

12 files changed

+62
-49
lines changed

Zend/tests/gh10168/assign_prop.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
--TEST--
22
GH-10168: Assign prop
3-
--XFAIL--
43
--FILE--
54
<?php
65

Zend/tests/gh10168/assign_prop_ref.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
--TEST--
22
GH-10168: Assign prop ref
3-
--XFAIL--
43
--FILE--
54
<?php
65

Zend/tests/gh10168/assign_prop_ref_with_prop_ref.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
--TEST--
22
GH-10168: Assign prop ref with prop ref
3-
--XFAIL--
43
--FILE--
54
<?php
65

Zend/tests/gh10168/assign_prop_with_prop_ref.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
--TEST--
22
GH-10168: Assign prop with prop ref
3-
--XFAIL--
43
--FILE--
54
<?php
65

Zend/tests/gh10168/assign_untyped_prop.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
--TEST--
22
GH-10168: Assign prop
3-
--XFAIL--
43
--FILE--
54
<?php
65

Zend/tests/gh10168/assign_untyped_prop_ref.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
--TEST--
22
GH-10168: Assign prop ref
3-
--XFAIL--
43
--FILE--
54
<?php
65

Zend/tests/gh10168/assign_untyped_prop_ref_with_prop_ref.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
--TEST--
22
GH-10168: Assign prop ref with prop ref
3-
--XFAIL--
43
--FILE--
54
<?php
65

Zend/tests/gh10168/assign_untyped_prop_with_prop_ref.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
--TEST--
22
GH-10168: Assign prop with prop ref
3-
--XFAIL--
43
--FILE--
54
<?php
65

Zend/zend_object_handlers.c

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -839,9 +839,30 @@ ZEND_API zval *zend_std_write_property(zend_object *zobj, zend_string *name, zva
839839
value = &tmp;
840840
}
841841

842-
found:
843-
variable_ptr = zend_assign_to_variable(
844-
variable_ptr, value, IS_TMP_VAR, property_uses_strict_types());
842+
found:;
843+
zend_refcounted *garbage = NULL;
844+
845+
variable_ptr = zend_assign_to_variable_ex(
846+
variable_ptr, value, IS_TMP_VAR, property_uses_strict_types(), &garbage);
847+
848+
if (garbage) {
849+
if (GC_DELREF(garbage) == 0) {
850+
zend_execute_data *execute_data = EG(current_execute_data);
851+
// Assign to result variable before calling the destructor as it may release the object
852+
if (execute_data
853+
&& EX(func)
854+
&& ZEND_USER_CODE(EX(func)->common.type)
855+
&& EX(opline)
856+
&& EX(opline)->opcode == ZEND_ASSIGN_OBJ
857+
&& EX(opline)->result_type) {
858+
ZVAL_COPY_DEREF(EX_VAR(EX(opline)->result.var), variable_ptr);
859+
variable_ptr = NULL;
860+
}
861+
rc_dtor_func(garbage);
862+
} else {
863+
gc_check_possible_root_no_ref(garbage);
864+
}
865+
}
845866
goto exit;
846867
}
847868
if (Z_PROP_FLAG_P(variable_ptr) & IS_PROP_UNINIT) {

Zend/zend_vm_def.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2494,7 +2494,7 @@ ZEND_VM_C_LABEL(fast_assign_obj):
24942494
}
24952495

24962496
ZEND_VM_C_LABEL(free_and_exit_assign_obj):
2497-
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
2497+
if (UNEXPECTED(RETURN_VALUE_USED(opline)) && value) {
24982498
ZVAL_COPY_DEREF(EX_VAR(opline->result.var), value);
24992499
}
25002500
FREE_OP_DATA();

0 commit comments

Comments
 (0)