Skip to content

Commit bf3e772

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fix memory leak when yielding from non-iterable
2 parents 571f6a5 + d179e34 commit bf3e772

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Yield from non-iterable
3+
--FILE--
4+
<?php
5+
6+
function gen() {
7+
yield from new stdClass;
8+
}
9+
10+
try {
11+
gen()->current();
12+
} catch (Error $e) {
13+
echo $e->getMessage(), "\n";
14+
}
15+
16+
?>
17+
--EXPECT--
18+
Can use "yield from" only with arrays and Traversables

Zend/zend_vm_def.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7906,6 +7906,7 @@ ZEND_VM_HANDLER(166, ZEND_YIELD_FROM, CONST|TMP|VAR|CV, ANY)
79067906
}
79077907
} else {
79087908
zend_throw_error(NULL, "Can use \"yield from\" only with arrays and Traversables");
7909+
FREE_OP1();
79097910
UNDEF_RESULT();
79107911
HANDLE_EXCEPTION();
79117912
}

Zend/zend_vm_execute.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4483,6 +4483,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_YIELD_FROM_SPEC_CONST_HANDLER(
44834483
}
44844484
} else {
44854485
zend_throw_error(NULL, "Can use \"yield from\" only with arrays and Traversables");
4486+
44864487
UNDEF_RESULT();
44874488
HANDLE_EXCEPTION();
44884489
}
@@ -18539,6 +18540,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_YIELD_FROM_SPEC_TMP_HANDLER(ZE
1853918540
}
1854018541
} else {
1854118542
zend_throw_error(NULL, "Can use \"yield from\" only with arrays and Traversables");
18543+
zval_ptr_dtor_nogc(free_op1);
1854218544
UNDEF_RESULT();
1854318545
HANDLE_EXCEPTION();
1854418546
}
@@ -21954,6 +21956,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_YIELD_FROM_SPEC_VAR_HANDLER(ZE
2195421956
}
2195521957
} else {
2195621958
zend_throw_error(NULL, "Can use \"yield from\" only with arrays and Traversables");
21959+
zval_ptr_dtor_nogc(free_op1);
2195721960
UNDEF_RESULT();
2195821961
HANDLE_EXCEPTION();
2195921962
}
@@ -38123,6 +38126,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_YIELD_FROM_SPEC_CV_HANDLER(ZEN
3812338126
}
3812438127
} else {
3812538128
zend_throw_error(NULL, "Can use \"yield from\" only with arrays and Traversables");
38129+
3812638130
UNDEF_RESULT();
3812738131
HANDLE_EXCEPTION();
3812838132
}

0 commit comments

Comments
 (0)