Skip to content

Commit f8f0a65

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Fix incorrect optimization that leads to memory leak
2 parents 1f03deb + 230de77 commit f8f0a65

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

Zend/Optimizer/sccp.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2258,7 +2258,9 @@ static int try_remove_definition(sccp_ctx *ctx, int var_num, zend_ssa_var *var,
22582258
removed_ops = remove_call(ctx, opline, ssa_op);
22592259
} else if (opline->opcode == ZEND_TYPE_CHECK
22602260
&& (opline->op1_type & (IS_VAR|IS_TMP_VAR))
2261-
&& !value_known(&ctx->values[ssa_op->op1_use])) {
2261+
&& (!value_known(&ctx->values[ssa_op->op1_use])
2262+
|| IS_PARTIAL_ARRAY(&ctx->values[ssa_op->op1_use])
2263+
|| IS_PARTIAL_OBJECT(&ctx->values[ssa_op->op1_use]))) {
22622264
/* For TYPE_CHECK we may compute the result value without knowing the
22632265
* operand, based on type inference information. Make sure the operand is
22642266
* freed and leave further cleanup to DCE. */

ext/opcache/tests/opt/sccp_034.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
SCCP 034: memory leak
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
--FILE--
8+
<?php
9+
is_array(["$y $y"]);
10+
?>
11+
DONE
12+
--EXPECTF--
13+
Warning: Undefined variable $y in %ssccp_034.php on line 2
14+
15+
Warning: Undefined variable $y in %ssccp_034.php on line 2
16+
DONE

0 commit comments

Comments
 (0)