Skip to content

Commit 26c7c82

Browse files
committed
Fix crash when memory limit is exceeded during generator initialization
1 parent 2b03846 commit 26c7c82

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

Zend/tests/generators/gh9801.phpt

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Bug GH-9801 (Crash when memory limit is exceeded during generator initialization)
3+
--INI--
4+
memory_limit=16m
5+
--FILE--
6+
<?php
7+
8+
function a() {
9+
yield from a();
10+
}
11+
12+
foreach(a() as $v);
13+
--EXPECTF--
14+
Fatal error: Allowed memory size of %d bytes exhausted %s

Zend/zend_vm_def.h

+1
Original file line numberDiff line numberDiff line change
@@ -4414,6 +4414,7 @@ ZEND_VM_HANDLER(139, ZEND_GENERATOR_CREATE, ANY, ANY)
44144414
zend_execute_data *gen_execute_data;
44154415
uint32_t num_args, used_stack, call_info;
44164416

4417+
SAVE_OPLINE();
44174418
object_init_ex(return_value, zend_ce_generator);
44184419

44194420
/*

Zend/zend_vm_execute.h

+1
Original file line numberDiff line numberDiff line change
@@ -2022,6 +2022,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_GENERATOR_CREATE_SPEC_HANDLER(
20222022
zend_execute_data *gen_execute_data;
20232023
uint32_t num_args, used_stack, call_info;
20242024

2025+
SAVE_OPLINE();
20252026
object_init_ex(return_value, zend_ce_generator);
20262027

20272028
/*

0 commit comments

Comments
 (0)