Skip to content

Commit 218da70

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Fix memory leak
2 parents 4b884be + 172ac0a commit 218da70

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

Zend/Optimizer/dfa_pass.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,9 @@ static bool opline_supports_assign_contraction(
353353
return opline->op1_type != IS_CV || opline->op1.var != cv_var;
354354
}
355355

356-
if (opline->opcode == ZEND_ASSIGN_OP
356+
if ((opline->opcode == ZEND_ASSIGN_OP
357+
|| opline->opcode == ZEND_ASSIGN_OBJ
358+
|| opline->opcode == ZEND_ASSIGN_DIM)
357359
&& opline->op1_type == IS_CV
358360
&& opline->op1.var == cv_var
359361
&& zend_may_throw(opline, &ssa->ops[ssa->vars[src_var].definition], op_array, ssa)) {
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
ASSIGN_OP 001: Incrrect optimization of ASSIGN_OBJ may lead to memory leak
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
--FILE--
8+
<?php
9+
function test() {
10+
$a .= $a += $y;
11+
$a = $a->y = '';
12+
}
13+
test();
14+
?>
15+
--EXPECTF--
16+
Warning: Undefined variable $y in %sassign_obj_001.php on line 3
17+
18+
Warning: Undefined variable $a in %sassign_obj_001.php on line 3
19+
20+
Fatal error: Uncaught Error: Attempt to assign property "y" on string in %sassign_obj_001.php:4
21+
Stack trace:
22+
#0 %sassign_obj_001.php(6): test()
23+
#1 {main}
24+
thrown in %sassign_obj_001.php on line 4

0 commit comments

Comments
 (0)