Skip to content

Commit 9aa862f

Browse files
dstogoviluuu1994
authored andcommitted
Delay destructor for zend_std_write_property
1 parent 278d651 commit 9aa862f

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
@@ -841,9 +841,30 @@ ZEND_API zval *zend_std_write_property(zend_object *zobj, zend_string *name, zva
841841
value = &tmp;
842842
}
843843

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