Skip to content

Commit b996436

Browse files
committed
Fix a class inheritence leak, when using static varibles in a parent class member function
1 parent 3b86ea7 commit b996436

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

Zend/zend_compile.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,17 @@ void do_return(znode *expr, int do_end_vparse CLS_DC)
998998
static void function_add_ref(zend_function *function)
999999
{
10001000
if (function->type == ZEND_USER_FUNCTION) {
1001-
(*((zend_op_array *) function)->refcount)++;
1001+
zend_op_array *op_array = &function->op_array;
1002+
1003+
(*op_array->refcount)++;
1004+
if (op_array->static_variables) {
1005+
HashTable *static_variables = op_array->static_variables;
1006+
zval *tmp_zval;
1007+
1008+
op_array->static_variables = (HashTable *) emalloc(sizeof(HashTable));
1009+
zend_hash_init(op_array->static_variables, 2, NULL, ZVAL_PTR_DTOR, 0);
1010+
zend_hash_copy(op_array->static_variables, static_variables, (void (*)(void *)) zval_add_ref, (void *) &tmp_zval, sizeof(zval *));
1011+
}
10021012
}
10031013
}
10041014

Zend/zend_opcode.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ ZEND_API void destroy_op_array(zend_op_array *op_array)
153153
zend_op *opline = op_array->opcodes;
154154
zend_op *end = op_array->opcodes+op_array->last;
155155

156+
if (op_array->static_variables) {
157+
zend_hash_destroy(op_array->static_variables);
158+
efree(op_array->static_variables);
159+
}
160+
156161
if (--(*op_array->refcount)>0) {
157162
return;
158163
}
@@ -184,10 +189,6 @@ ZEND_API void destroy_op_array(zend_op_array *op_array)
184189
if (op_array->brk_cont_array) {
185190
efree(op_array->brk_cont_array);
186191
}
187-
if (op_array->static_variables) {
188-
zend_hash_destroy(op_array->static_variables);
189-
efree(op_array->static_variables);
190-
}
191192
zend_llist_apply_with_argument(&zend_extensions, (void (*)(void *, void *)) zend_extension_op_array_dtor_handler, op_array);
192193
}
193194

0 commit comments

Comments
 (0)