Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c87face

Browse files
Fix printing backtrace during generator closing
Fixes GH-15851
1 parent 422aa17 commit c87face

File tree

3 files changed

+46
-6
lines changed

3 files changed

+46
-6
lines changed

‎Zend/tests/gh15851.phpt‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
GH-15851: Access on NULL when printing backtrace with freed generator
3+
--FILE--
4+
<?php
5+
6+
class Foo {
7+
public function __destruct() {
8+
debug_print_backtrace();
9+
}
10+
}
11+
12+
function bar() {
13+
yield from foo();
14+
}
15+
16+
function foo() {
17+
$foo = new Foo();
18+
yield;
19+
}
20+
21+
$gen = bar();
22+
foreach ($gen as $dummy);
23+
24+
?>
25+
--EXPECTF--
26+
#0 %s(%d): Foo->__destruct()
27+
#1 %s(%d): foo()
28+
#2 %s(%d): bar()

‎Zend/zend_vm_def.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4548,11 +4548,13 @@ ZEND_VM_HANDLER(161, ZEND_GENERATOR_RETURN, CONST|TMP|VAR|CV, ANY, SPEC(OBSERVER
45484548

45494549
ZEND_OBSERVER_FCALL_END(generator->execute_data, &generator->retval);
45504550

4551-
EG(current_execute_data) = EX(prev_execute_data);
4551+
zend_execute_data*prev_execute_data = EX(prev_execute_data);
45524552

45534553
/* Close the generator to free up resources */
45544554
zend_generator_close(generator, 1);
45554555

4556+
EG(current_execute_data) = prev_execute_data;
4557+
45564558
/* Pass execution back to handling code */
45574559
ZEND_VM_RETURN();
45584560
}

‎Zend/zend_vm_execute.h‎

Lines changed: 15 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /