Skip to content

Commit 5b0d86e

Browse files
committed
Safe destruction (variables and arguments may need to be cuptured by exception)
1 parent e44ccde commit 5b0d86e

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

Zend/zend_execute.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1806,7 +1806,15 @@ static zend_always_inline void i_free_compiled_variables(zend_execute_data *exec
18061806
zval *cv = EX_VAR_NUM(0);
18071807
zval *end = cv + EX(func)->op_array.last_var;
18081808
while (EXPECTED(cv != end)) {
1809-
zval_ptr_dtor(cv);
1809+
if (Z_REFCOUNTED_P(cv)) {
1810+
if (!Z_DELREF_P(cv)) {
1811+
zend_refcounted *r = Z_COUNTED_P(cv);
1812+
ZVAL_NULL(cv);
1813+
zval_dtor_func_for_ptr(r);
1814+
} else {
1815+
GC_ZVAL_CHECK_POSSIBLE_ROOT(cv);
1816+
}
1817+
}
18101818
cv++;
18111819
}
18121820
}

Zend/zend_execute.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,15 @@ static zend_always_inline void zend_vm_stack_free_extra_args_ex(uint32_t call_in
199199
zval *p = end + (ZEND_CALL_NUM_ARGS(call) - call->func->op_array.num_args);
200200
do {
201201
p--;
202-
i_zval_ptr_dtor(p ZEND_FILE_LINE_CC);
202+
if (Z_REFCOUNTED_P(p)) {
203+
if (!Z_DELREF_P(p)) {
204+
zend_refcounted *r = Z_COUNTED_P(p);
205+
ZVAL_NULL(p);
206+
zval_dtor_func_for_ptr(r);
207+
} else {
208+
GC_ZVAL_CHECK_POSSIBLE_ROOT(p);
209+
}
210+
}
203211
} while (p != end);
204212
}
205213
}
@@ -219,7 +227,13 @@ static zend_always_inline void zend_vm_stack_free_args(zend_execute_data *call)
219227

220228
do {
221229
p--;
222-
zval_ptr_dtor_nogc(p);
230+
if (Z_REFCOUNTED_P(p)) {
231+
if (!Z_DELREF_P(p)) {
232+
zend_refcounted *r = Z_COUNTED_P(p);
233+
ZVAL_NULL(p);
234+
zval_dtor_func_for_ptr(r);
235+
}
236+
}
223237
} while (p != end);
224238
}
225239
}

0 commit comments

Comments
 (0)