Skip to content

Commit

Permalink
JIT: Fixed memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
dstogov committed Nov 17, 2021
1 parent 48a65fe commit fac78ee
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ext/opcache/jit/zend_jit_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,7 @@ static void ZEND_FASTCALL zend_jit_fast_assign_concat_helper(zval *op1, zval *op

do {
if (Z_REFCOUNTED_P(op1)) {
if (GC_REFCOUNT(Z_STR_P(op1)) == 1) {
if (GC_REFCOUNT(Z_STR_P(op1)) == 1 && EXPECTED(Z_STR_P(op1) != Z_STR_P(op2))) {
result_str = perealloc(Z_STR_P(op1), ZEND_MM_ALIGNED_SIZE(_ZSTR_STRUCT_SIZE(result_len)), 0);
ZSTR_LEN(result_str) = result_len;
zend_string_forget_hash_val(result_str);
Expand Down
2 changes: 2 additions & 0 deletions ext/opcache/jit/zend_jit_x86.dasc
Original file line number Diff line number Diff line change
Expand Up @@ -5323,6 +5323,8 @@ static int zend_jit_concat_helper(dasm_State **Dst,
}
| LOAD_ZVAL_ADDR FCARG2a, op2_addr
| EXT_CALL zend_jit_fast_assign_concat_helper, r0
/* concatination with itself may reduce refcount */
op2_info |= MAY_BE_RC1;
} else {
if (Z_REG(res_addr) != ZREG_FCARG1a || Z_OFFSET(res_addr) != 0) {
| LOAD_ZVAL_ADDR FCARG1a, res_addr
Expand Down
19 changes: 19 additions & 0 deletions ext/opcache/tests/jit/assign_op_006.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
JIT ASSIGN_OP: 006 concationation with itself
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.file_update_protection=0
opcache.jit_buffer_size=1M
--FILE--
<?php
function test($a) {
for ($i = 0; $i < 2; $i++) {
$a .= $a = $a;
}
}
test("");
?>
DONE
--EXPECT--
DONE

0 comments on commit fac78ee

Please sign in to comment.