8000 Properly release `zend_ast_op_array` in OPcache · php/php-src@9a7cd28 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9a7cd28

Browse files
iluuu1994TimWolla
authored andcommitted
Properly release zend_ast_op_array in OPcache
[Diff by Ilija, commit message by Tim]
1 parent 6e076a4 commit 9a7cd28

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

ext/opcache/zend_persist.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ static zend_ast *zend_persist_ast(zend_ast *ast)
190190
node = (zend_ast *) copy;
191191
} else if (ast->kind == ZEND_AST_OP_ARRAY) {
192192
zend_ast_op_array *copy = zend_shared_memdup(ast, sizeof(zend_ast_op_array));
193+
/* We're holding a separate reference to the op_array in the AST. Release it
194+
* early because zend_persist_op_array() is destructive. */
195+
destroy_op_array(copy->op_array);
193196
zval z;
194197
ZVAL_PTR(&z, copy->op_array);
195198
zend_persist_op_array(&z);

ext/opcache/zend_persist_calc.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ static void zend_persist_ast_calc(zend_ast *ast)
9191
zval z;
9292
ZVAL_PTR(&z, zend_ast_get_op_array(ast)->op_array);
9393
zend_persist_op_array_calc(&z);
94+
95+
/* If op_array is shared, the function name refcount is still incremented for each use,
96+
* so we need to release it here. We remembered the original function name in xlat. */
97+
zend_string *old_function_name =
98+
zend_shared_alloc_get_xlat_entry(&zend_ast_get_op_array(ast)->op_array->function_name);
99+
if (old_function_name) {
100+
zend_string_release_ex(old_function_name, 0);
101+
}
94102
} else if (zend_ast_is_decl(ast)) {
95103
/* Not implemented. */
96104
ZEND_UNREACHABLE();

0 commit comments

Comments
 (0)
0