diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index 53aa7a821f69..20891c8cb68f 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -4534,7 +4534,7 @@ ZEND_VM_HANDLER(139, ZEND_GENERATOR_CREATE, ANY, ANY) if ((call_info & Z_TYPE_MASK) == IS_OBJECT && (!(call_info & (ZEND_CALL_CLOSURE|ZEND_CALL_RELEASE_THIS)) /* Bug #72523 */ - || UNEXPECTED(zend_execute_ex != execute_ex))) { + || (call_info & (ZEND_CALL_DYNAMIC|ZEND_CALL_TOP)) == ZEND_CALL_TOP)) { ZEND_ADD_CALL_FLAG_EX(call_info, ZEND_CALL_RELEASE_THIS); Z_ADDREF(gen_execute_data->This); } diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 2c86a94134c0..89be7af7040c 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -2177,7 +2177,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_GENERATOR_CREATE_SPEC_HANDLER( if ((call_info & Z_TYPE_MASK) == IS_OBJECT && (!(call_info & (ZEND_CALL_CLOSURE|ZEND_CALL_RELEASE_THIS)) /* Bug #72523 */ - || UNEXPECTED(zend_execute_ex != execute_ex))) { + || (call_info & (ZEND_CALL_DYNAMIC|ZEND_CALL_TOP)) == ZEND_CALL_TOP)) { ZEND_ADD_CALL_FLAG_EX(call_info, ZEND_CALL_RELEASE_THIS); Z_ADDREF(gen_execute_data->This); } diff --git a/sapi/phpdbg/tests/gh12837.phpt b/sapi/phpdbg/tests/gh12837.phpt new file mode 100644 index 000000000000..57a631c8849c --- /dev/null +++ b/sapi/phpdbg/tests/gh12837.phpt @@ -0,0 +1,44 @@ +--TEST-- +GH-12837 (Combination of phpdbg and Generator method causes memory leak) +--CREDITS-- +ngyuki +--FILE-- +iterate()); gc_collect_cycles(); +$arr = iterator_to_array((new A())->iterate()); gc_collect_cycles(); +$arr = iterator_to_array((new A())->iterate()); gc_collect_cycles(); + +var_dump('exit'); +?> +--PHPDBG-- +r +q +--EXPECTF-- +[Successful compilation of %s] +prompt> string(11) "__construct" +string(10) "__destruct" +string(11) "__construct" +string(10) "__destruct" +string(11) "__construct" +string(10) "__destruct" +string(4) "exit" +[Script ended normally] +prompt>