Skip to content

Commit 462d00f

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Fix memory leak
2 parents 72d8370 + c430116 commit 462d00f

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
@@ -2067,8 +2067,39 @@ static int try_remove_definition(sccp_ctx *ctx, int var_num, zend_ssa_var *var,
20672067
}
20682068
return 0;
20692069
}
2070-
if (ssa_op->op1_def >= 0
2071-
|| ssa_op->op2_def >= 0) {
2070+
if (ssa_op->op1_def >= 0 || ssa_op->op2_def >= 0) {
2071+
if (var->use_chain < 0 && var->phi_use_chain == NULL) {
2072+
switch (opline->opcode) {
2073+
case ZEND_ASSIGN:
2074+
case ZEND_ASSIGN_REF:
2075+
case ZEND_ASSIGN_DIM:
2076+
case ZEND_ASSIGN_OBJ:
2077+
case ZEND_ASSIGN_OBJ_REF:
2078+
case ZEND_ASSIGN_STATIC_PROP:
2079+
case ZEND_ASSIGN_STATIC_PROP_REF:
2080+
case ZEND_ASSIGN_OP:
2081+
case ZEND_ASSIGN_DIM_OP:
2082+
case ZEND_ASSIGN_OBJ_OP:
2083+
case ZEND_ASSIGN_STATIC_PROP_OP:
2084+
case ZEND_PRE_INC:
2085+
case ZEND_PRE_DEC:
2086+
case ZEND_PRE_INC_OBJ:
2087+
case ZEND_PRE_DEC_OBJ:
2088+
case ZEND_DO_ICALL:
2089+
case ZEND_DO_UCALL:
2090+
case ZEND_DO_FCALL_BY_NAME:
2091+
case ZEND_DO_FCALL:
2092+
case ZEND_INCLUDE_OR_EVAL:
2093+
case ZEND_YIELD:
2094+
case ZEND_YIELD_FROM:
2095+
case ZEND_ASSERT_CHECK:
2096+
opline->result_type = IS_UNUSED;
2097+
zend_ssa_remove_result_def(ssa, ssa_op);
2098+
break;
2099+
default:
2100+
break;
2101+
}
2102+
}
20722103
/* we cannot remove instruction that defines other variables */
20732104
return 0;
20742105
} 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)