]> granicus.if.org Git - php/commitdiff
Fix memory leak when yielding from non-iterable
authorNikita Popov <nikita.ppv@gmail.com>
Wed, 26 Aug 2020 09:32:01 +0000 (11:32 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Wed, 26 Aug 2020 09:32:01 +0000 (11:32 +0200)
Zend/tests/generators/yield_from_non_iterable.phpt [new file with mode: 0644]
Zend/zend_vm_def.h
Zend/zend_vm_execute.h

diff --git a/Zend/tests/generators/yield_from_non_iterable.phpt b/Zend/tests/generators/yield_from_non_iterable.phpt
new file mode 100644 (file)
index 0000000..705bcae
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--
+Yield from non-iterable
+--FILE--
+<?php
+
+function gen() {
+    yield from new stdClass;
+}
+
+try {
+    gen()->current();
+} catch (Error $e) {
+    echo $e->getMessage(), "\n";
+}
+
+?>
+--EXPECT--
+Can use "yield from" only with arrays and Traversables
index 9c46476b6add184aff03345664c20b8f9a878072..70e33039da0cb592dd462685f12ed2570e511162 100644 (file)
@@ -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();
        }
index a84cfe3d4bb3f084b0a09deea1e07a87d9edaac9..9d7515e9d05275047e93c8309fc9d983c8145837 100644 (file)
@@ -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();
        }