Skip to content

Commit 84ea0aa

Browse files
committed
Fix memory leak
This fixes oss-fuzz #47448
1 parent 0537560 commit 84ea0aa

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

ext/opcache/Optimizer/sccp.c

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2234,8 +2234,39 @@ static int try_remove_definition(sccp_ctx *ctx, int var_num, zend_ssa_var *var,
22342234
}
22352235

22362236
if (ssa_op->result_def == var_num) {
2237-
if (ssa_op->op1_def >= 0
2238-
|| ssa_op->op2_def >= 0) {
2237+
if (ssa_op->op1_def >= 0 || ssa_op->op2_def >= 0) {
2238+
if (var->use_chain < 0 && var->phi_use_chain == NULL) {
2239+
switch (opline->opcode) {
2240+
case ZEND_ASSIGN:
2241+
case ZEND_ASSIGN_REF:
2242+
case ZEND_ASSIGN_DIM:
2243+
case ZEND_ASSIGN_OBJ:
2244+
case ZEND_ASSIGN_OBJ_REF:
2245+
case ZEND_ASSIGN_STATIC_PROP:
2246+
case ZEND_ASSIGN_STATIC_PROP_REF:
2247+
case ZEND_ASSIGN_OP:
2248+
case ZEND_ASSIGN_DIM_OP:
2249+
case ZEND_ASSIGN_OBJ_OP:
2250+
case ZEND_ASSIGN_STATIC_PROP_OP:
2251+
case ZEND_PRE_INC:
2252+
case ZEND_PRE_DEC:
2253+
case ZEND_PRE_INC_OBJ:
2254+
case ZEND_PRE_DEC_OBJ:
2255+
case ZEND_DO_ICALL:
2256+
case ZEND_DO_UCALL:
2257+
case ZEND_DO_FCALL_BY_NAME:
2258+
case ZEND_DO_FCALL:
2259+
case ZEND_INCLUDE_OR_EVAL:
2260+
case ZEND_YIELD:
2261+
case ZEND_YIELD_FROM:
2262+
case ZEND_ASSERT_CHECK:
2263+
opline->result_type = IS_UNUSED;
2264+
zend_ssa_remove_result_def(ssa, ssa_op);
2265+
break;
2266+
default:
2267+
break;
2268+
}
2269+
}
22392270
/* we cannot remove instruction that defines other variables */
22402271
return 0;
22412272
} 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)