Skip to content

Commit 61a38bb

Browse files
committed
SCCP: Fix leak when determining TYPE_CHECK from type info
As TYPE_CHECK is the only opcode where we do something like this, I'm adding this hack.
1 parent de7d025 commit 61a38bb

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

ext/opcache/Optimizer/sccp.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2203,6 +2203,14 @@ static int try_remove_definition(sccp_ctx *ctx, int var_num, zend_ssa_var *var,
22032203
zend_ssa_remove_result_def(ssa, ssa_op);
22042204
if (opline->opcode == ZEND_DO_ICALL) {
22052205
removed_ops = remove_call(ctx, opline, ssa_op);
2206+
} else if (opline->opcode == ZEND_TYPE_CHECK
2207+
&& !value_known(&ctx->values[ssa_op->op1_use])) {
2208+
/* For TYPE_CHECK we may compute the result value without knowing the
2209+
* operand, based on type inference information. Make sure the operand is
2210+
* freed and leave further cleanup to DCE. */
2211+
opline->opcode = ZEND_FREE;
2212+
opline->result_type = IS_UNUSED;
2213+
removed_ops++;
22062214
} else {
22072215
zend_ssa_remove_instr(ssa, opline, ssa_op);
22082216
removed_ops++;

ext/opcache/tests/opt/sccp_030.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
SCCP 030: TYPE_CHECK inferred from type inference info
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
opcache.opt_debug_level=0
8+
--SKIPIF--
9+
<?php require_once('skipif.inc'); ?>
10+
--FILE--
11+
<?php
12+
13+
var_dump(is_string(sys_get_temp_dir()));
14+
15+
?>
16+
--EXPECT--
17+
bool(true)

0 commit comments

Comments
 (0)