Skip to content

Commit c430116

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Fix memory leak
2 parents aad5fba + 84ea0aa commit c430116

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

Zend/Optimizer/sccp.c

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2214,8 +2214,39 @@ static int try_remove_definition(sccp_ctx *ctx, int var_num, zend_ssa_var *var,
22142214
}
22152215
return 0;
22162216
}
2217-
if (ssa_op->op1_def >= 0
2218-
|| ssa_op->op2_def >= 0) {
2217+
if (ssa_op->op1_def >= 0 || ssa_op->op2_def >= 0) {
2218+
if (var->use_chain < 0 && var->phi_use_chain == NULL) {
2219+
switch (opline->opcode) {
2220+
case ZEND_ASSIGN:
2221+
case ZEND_ASSIGN_REF:
2222+
case ZEND_ASSIGN_DIM:
2223+
case ZEND_ASSIGN_OBJ:
2224+
case ZEND_ASSIGN_OBJ_REF:
2225+
case ZEND_ASSIGN_STATIC_PROP:
2226+
case ZEND_ASSIGN_STATIC_PROP_REF:
2227+
case ZEND_ASSIGN_OP:
2228+
case ZEND_ASSIGN_DIM_OP:
2229+
case ZEND_ASSIGN_OBJ_OP:
2230+
case ZEND_ASSIGN_STATIC_PROP_OP:
2231+
case ZEND_PRE_INC:
2232+
case ZEND_PRE_DEC:
2233+
case ZEND_PRE_INC_OBJ:
2234+
case ZEND_PRE_DEC_OBJ:
2235+
case ZEND_DO_ICALL:
2236+
case ZEND_DO_UCALL:
2237+
case ZEND_DO_FCALL_BY_NAME:
2238+
case ZEND_DO_FCALL:
2239+
case ZEND_INCLUDE_OR_EVAL:
2240+
case ZEND_YIELD:
2241+
case ZEND_YIELD_FROM:
2242+
case ZEND_ASSERT_CHECK:
2243+
opline->result_type = IS_UNUSED;
2244+
zend_ssa_remove_result_def(ssa, ssa_op);
2245+
break;
2246+
default:
2247+
break;
2248+
}
2249+
}
22192250
/* we cannot remove instruction that defines other variables */
22202251
return 0;
22212252
} else if (opline->opcode == ZEND_JMPZ_EX

ext/opcache/tests/opt/sccp_040.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
SCCP 040: Memory leak
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
--FILE--
8+
<?php
9+
function f() {
10+
$y[] = $arr[] = array($y);
11+
$arr();
12+
}
13+
f();
14+
?>
15+
--EXPECTF--
16+
Warning: Undefined variable $y in %ssccp_040.php on line 3
17+
18+
Fatal error: Uncaught Error: Array callback must have exactly two elements in %ssccp_040.php:4
19+
Stack trace:
20+
#0 %ssccp_040.php(6): f()
21+
#1 {main}
22+
thrown in %ssccp_040.php on line 4

0 commit comments

Comments
 (0)