From: Nikita Popov Date: Wed, 26 Aug 2020 09:32:01 +0000 (+0200) Subject: Fix memory leak when yielding from non-iterable X-Git-Tag: php-7.3.23RC1~25 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d179e34e42e8e9cc5250ba2265fb50a8187bb6b1;p=php Fix memory leak when yielding from non-iterable --- diff --git a/Zend/tests/generators/yield_from_non_iterable.phpt b/Zend/tests/generators/yield_from_non_iterable.phpt new file mode 100644 index 0000000000..705bcaec35 --- /dev/null +++ b/Zend/tests/generators/yield_from_non_iterable.phpt @@ -0,0 +1,18 @@ +--TEST-- +Yield from non-iterable +--FILE-- +current(); +} catch (Error $e) { + echo $e->getMessage(), "\n"; +} + +?> +--EXPECT-- +Can use "yield from" only with arrays and Traversables diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index 9c46476b6a..70e33039da 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -7371,6 +7371,7 @@ ZEND_VM_HANDLER(142, ZEND_YIELD_FROM, CONST|TMP|VAR|CV, ANY) } } else { zend_throw_error(NULL, "Can use \"yield from\" only with arrays and Traversables"); + FREE_OP1(); UNDEF_RESULT(); HANDLE_EXCEPTION(); } diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index a84cfe3d4b..9d7515e9d0 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -3707,6 +3707,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_YIELD_FROM_SPEC_CONST_HANDLER( } } else { zend_throw_error(NULL, "Can use \"yield from\" only with arrays and Traversables"); + UNDEF_RESULT(); HANDLE_EXCEPTION(); } @@ -18346,6 +18347,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_YIELD_FROM_SPEC_TMP_HANDLER(ZE } } else { zend_throw_error(NULL, "Can use \"yield from\" only with arrays and Traversables"); + zval_ptr_dtor_nogc(free_op1); UNDEF_RESULT(); HANDLE_EXCEPTION(); } @@ -21672,6 +21674,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_YIELD_FROM_SPEC_VAR_HANDLER(ZE } } else { zend_throw_error(NULL, "Can use \"yield from\" only with arrays and Traversables"); + zval_ptr_dtor_nogc(free_op1); UNDEF_RESULT(); HANDLE_EXCEPTION(); } @@ -37896,6 +37899,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_YIELD_FROM_SPEC_CV_HANDLER(ZEN } } else { zend_throw_error(NULL, "Can use \"yield from\" only with arrays and Traversables"); + UNDEF_RESULT(); HANDLE_EXCEPTION(); }