Skip to content

Commit d179e34

Browse files
committed
Fix memory leak when yielding from non-iterable
1 parent 3324bb8 commit d179e34

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
@@ -7371,6 +7371,7 @@ ZEND_VM_HANDLER(142, ZEND_YIELD_FROM, CONST|TMP|VAR|CV, ANY)
73717371
}
73727372
} else {
73737373
zend_throw_error(NULL, "Can use \"yield from\" only with arrays and Traversables");
7374+
FREE_OP1();
73747375
UNDEF_RESULT();
73757376
HANDLE_EXCEPTION();
73767377
}

Zend/zend_vm_execute.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3707,6 +3707,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_YIELD_FROM_SPEC_CONST_HANDLER(
37073707
}
37083708
} else {
37093709
zend_throw_error(NULL, "Can use \"yield from\" only with arrays and Traversables");
3710+
37103711
UNDEF_RESULT();
37113712
HANDLE_EXCEPTION();
37123713
}
@@ -18346,6 +18347,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_YIELD_FROM_SPEC_TMP_HANDLER(ZE
1834618347
}
1834718348
} else {
1834818349
zend_throw_error(NULL, "Can use \"yield from\" only with arrays and Traversables");
18350+
zval_ptr_dtor_nogc(free_op1);
1834918351
UNDEF_RESULT();
1835018352
HANDLE_EXCEPTION();
1835118353
}
@@ -21672,6 +21674,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_YIELD_FROM_SPEC_VAR_HANDLER(ZE
2167221674
}
2167321675
} else {
2167421676
zend_throw_error(NULL, "Can use \"yield from\" only with arrays and Traversables");
21677+
zval_ptr_dtor_nogc(free_op1);
2167521678
UNDEF_RESULT();
2167621679
HANDLE_EXCEPTION();
2167721680
}
@@ -37896,6 +37899,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_YIELD_FROM_SPEC_CV_HANDLER(ZEN
3789637899
}
3789737900
} else {
3789837901
zend_throw_error(NULL, "Can use \"yield from\" only with arrays and Traversables");
37902+
3789937903
UNDEF_RESULT();
3790037904
HANDLE_EXCEPTION();
3790137905
}

0 commit comments

Comments
 (0)