Skip to content

Commit f922597

Browse files
committed
Merge branch 'PHP-8.2'
* PHP-8.2: Fix memory leak because of incorrect optimization
2 parents 2e3d13e + 0464524 commit f922597

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

Zend/Optimizer/block_pass.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,13 @@ static void zend_optimize_block(zend_basic_block *block, zend_op_array *op_array
256256
}
257257
break;
258258

259+
case ZEND_MATCH_ERROR:
260+
if (opline->op1_type == IS_TMP_VAR) {
261+
src = VAR_SOURCE(opline->op1);
262+
VAR_SOURCE(opline->op1) = NULL;
263+
}
264+
break;
265+
259266
case ZEND_FREE:
260267
if (opline->op1_type == IS_TMP_VAR) {
261268
src = VAR_SOURCE(opline->op1);

ext/opcache/tests/opt/match_002.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Match 002: memory leak because of incorrect optimization
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
--FILE--
8+
<?php
9+
match($y=y){};
10+
?>
11+
--EXPECTF--
12+
Fatal error: Uncaught Error: Undefined constant "y" in %smatch_002.php:2
13+
Stack trace:
14+
#0 {main}
15+
thrown in %smatch_002.php on line 2

0 commit comments

Comments
 (0)