Skip to content

Commit

Permalink
Fix incorrect optimization that leads to memory leak
Browse files Browse the repository at this point in the history
Fixes oss-fuzz #42221
  • Loading branch information
dstogov committed Dec 13, 2021
1 parent e79dbe1 commit 230de77
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ext/opcache/Optimizer/sccp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2279,7 +2279,9 @@ static int try_remove_definition(sccp_ctx *ctx, int var_num, zend_ssa_var *var,
removed_ops = remove_call(ctx, opline, ssa_op);
} else if (opline->opcode == ZEND_TYPE_CHECK
&& (opline->op1_type & (IS_VAR|IS_TMP_VAR))
&& !value_known(&ctx->values[ssa_op->op1_use])) {
&& (!value_known(&ctx->values[ssa_op->op1_use])
|| IS_PARTIAL_ARRAY(&ctx->values[ssa_op->op1_use])
|| IS_PARTIAL_OBJECT(&ctx->values[ssa_op->op1_use]))) {
/* For TYPE_CHECK we may compute the result value without knowing the
* operand, based on type inference information. Make sure the operand is
* freed and leave further cleanup to DCE. */
Expand Down
16 changes: 16 additions & 0 deletions ext/opcache/tests/opt/sccp_034.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
SCCP 034: memory leak
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.optimization_level=-1
--FILE--
<?php
is_array(["$y $y"]);
?>
DONE
--EXPECTF--
Warning: Undefined variable $y in %ssccp_034.php on line 2

Warning: Undefined variable $y in %ssccp_034.php on line 2
DONE

0 comments on commit 230de77

Please sign in to comment.