Skip to content

Commit 6ca49d4

Browse files
committed
fix memory leak in arena-alloc'd classes
This one was a doozy... apparently, methods cached by opcache are cleaned up differently and was resulting in a memory leak Signed-off-by: Robert Landers <landers.robert@gmail.com>
1 parent 69ca92c commit 6ca49d4

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

Zend/zend_compile.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8578,7 +8578,9 @@ static zend_op_array *zend_compile_func_decl_ex(
85788578
op_array->fn_flags |= ZEND_ACC_PRELOADED;
85798579
}
85808580

8581-
if (CG(file_context).current_namespace) {
8581+
/* Only set namespace_name for standalone functions, not for methods.
8582+
* Methods get their namespace from the class name at runtime via zend_get_caller_namespace(). */
8583+
if (CG(file_context).current_namespace && !CG(active_class_entry)) {
85828584
op_array->namespace_name = zend_string_copy(CG(file_context).current_namespace);
85838585
}
85848586

Zend/zend_language_scanner.l

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -609,10 +609,6 @@ static zend_op_array *zend_compile(int type)
609609
init_op_array(op_array, type, INITIAL_OP_ARRAY_SIZE);
610610
CG(active_op_array) = op_array;
611611

612-
if (CG(file_context).current_namespace) {
613-
op_array->namespace_name = zend_string_copy(CG(file_context).current_namespace);
614-
}
615-
616612
/* Use heap to not waste arena memory */
617613
op_array->fn_flags |= ZEND_ACC_HEAP_RT_CACHE;
618614

Zend/zend_opcode.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,10 @@ ZEND_API void destroy_op_array(zend_op_array *op_array)
567567
zend_string_release_ex(op_array->function_name, 0);
568568
}
569569

570+
if (op_array->namespace_name) {
571+
zend_string_release_ex(op_array->namespace_name, 0);
572+
}
573+
570574
if (!op_array->refcount || --(*op_array->refcount) > 0) {
571575
return;
572576
}
@@ -612,9 +616,6 @@ ZEND_API void destroy_op_array(zend_op_array *op_array)
612616
if (op_array->doc_comment) {
613617
zend_string_release_ex(op_array->doc_comment, 0);
614618
}
615-
if (op_array->namespace_name) {
616-
zend_string_release_ex(op_array->namespace_name, 0);
617-
}
618619
if (op_array->attributes) {
619620
zend_hash_release(op_array->attributes);
620621
}

0 commit comments

Comments
 (0)