Skip to content

Commit 156d3ae

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Fix memory leak
2 parents 2bed115 + 2b7431c commit 156d3ae

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

Zend/Optimizer/zend_inference.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2793,6 +2793,20 @@ static zend_always_inline int _zend_update_type_info(
27932793
tmp &= ~MAY_BE_REF;
27942794
tmp |= MAY_BE_NULL|MAY_BE_FALSE|MAY_BE_TRUE|MAY_BE_LONG|MAY_BE_DOUBLE|MAY_BE_STRING|MAY_BE_RC1|MAY_BE_RCN;
27952795
}
2796+
if ((tmp & (MAY_BE_RC1|MAY_BE_RCN)) == MAY_BE_RCN) {
2797+
/* refcount may be indirectly decremented. Make an exception if the result is used in the next instruction */
2798+
if (!ssa_opcodes) {
2799+
if (ssa->vars[ssa_op->result_def].use_chain < 0
2800+
|| opline + 1 != op_array->opcodes + ssa->vars[ssa_op->result_def].use_chain) {
2801+
tmp |= MAY_BE_RC1;
2802+
}
2803+
} else {
2804+
if (ssa->vars[ssa_op->result_def].use_chain < 0
2805+
|| opline + 1 != ssa_opcodes[ssa->vars[ssa_op->result_def].use_chain]) {
2806+
tmp |= MAY_BE_RC1;
2807+
}
2808+
}
2809+
}
27962810
UPDATE_SSA_TYPE(tmp, ssa_op->result_def);
27972811
COPY_SSA_OBJ_TYPE(ssa_op->op2_use, ssa_op->result_def);
27982812
}

ext/opcache/tests/jit/assign_052.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
JIT ASSIGN: incorrect reference counting
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.file_update_protection=0
7+
opcache.jit_buffer_size=1M
8+
opcache.protect_memory=1
9+
--FILE--
10+
<?php
11+
function foo(){
12+
for($cnt = 0; $cnt < 6; $cnt++) {
13+
$t[$i = $s][] = [] > $n[$i = $j] = $s = $a . $a = $f;
14+
}
15+
}
16+
@foo();
17+
?>
18+
DONE
19+
--EXPECT--
20+
DONE

0 commit comments

Comments
 (0)