Skip to content

Commit 2b7431c

Browse files
committed
Fix memory leak
Fixed oss-fuzz #45535
1 parent e20f955 commit 2b7431c

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

ext/opcache/Optimizer/zend_inference.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2748,6 +2748,20 @@ static zend_always_inline int _zend_update_type_info(
27482748
tmp &= ~MAY_BE_REF;
27492749
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;
27502750
}
2751+
if ((tmp & (MAY_BE_RC1|MAY_BE_RCN)) == MAY_BE_RCN) {
2752+
/* refcount may be indirectly decremented. Make an exception if the result is used in the next instruction */
2753+
if (!ssa_opcodes) {
2754+
if (ssa->vars[ssa_op->result_def].use_chain < 0
2755+
|| opline + 1 != op_array->opcodes + ssa->vars[ssa_op->result_def].use_chain) {
2756+
tmp |= MAY_BE_RC1;
2757+
}
2758+
} else {
2759+
if (ssa->vars[ssa_op->result_def].use_chain < 0
2760+
|| opline + 1 != ssa_opcodes[ssa->vars[ssa_op->result_def].use_chain]) {
2761+
tmp |= MAY_BE_RC1;
2762+
}
2763+
}
2764+
}
27512765
UPDATE_SSA_TYPE(tmp, ssa_op->result_def);
27522766
COPY_SSA_OBJ_TYPE(ssa_op->op2_use, ssa_op->result_def);
27532767
}

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)