Skip to content

Commit 0464524

Browse files
committed
Fix memory leak because of incorrect optimization
Fixes oss-fuzz #54488
1 parent e7b6c2e commit 0464524

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

Zend/Optimizer/block_pass.c

+7
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

+15
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)