Skip to content

Commit fac78ee

Browse files
committed
JIT: Fixed memory leak
1 parent 48a65fe commit fac78ee

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

ext/opcache/jit/zend_jit_helpers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1369,7 +1369,7 @@ static void ZEND_FASTCALL zend_jit_fast_assign_concat_helper(zval *op1, zval *op
13691369

13701370
do {
13711371
if (Z_REFCOUNTED_P(op1)) {
1372-
if (GC_REFCOUNT(Z_STR_P(op1)) == 1) {
1372+
if (GC_REFCOUNT(Z_STR_P(op1)) == 1 && EXPECTED(Z_STR_P(op1) != Z_STR_P(op2))) {
13731373
result_str = perealloc(Z_STR_P(op1), ZEND_MM_ALIGNED_SIZE(_ZSTR_STRUCT_SIZE(result_len)), 0);
13741374
ZSTR_LEN(result_str) = result_len;
13751375
zend_string_forget_hash_val(result_str);

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5323,6 +5323,8 @@ static int zend_jit_concat_helper(dasm_State **Dst,
53235323
}
53245324
| LOAD_ZVAL_ADDR FCARG2a, op2_addr
53255325
| EXT_CALL zend_jit_fast_assign_concat_helper, r0
5326+
/* concatination with itself may reduce refcount */
5327+
op2_info |= MAY_BE_RC1;
53265328
} else {
53275329
if (Z_REG(res_addr) != ZREG_FCARG1a || Z_OFFSET(res_addr) != 0) {
53285330
| LOAD_ZVAL_ADDR FCARG1a, res_addr
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
JIT ASSIGN_OP: 006 concationation with itself
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.file_update_protection=0
7+
opcache.jit_buffer_size=1M
8+
--FILE--
9+
<?php
10+
function test($a) {
11+
for ($i = 0; $i < 2; $i++) {
12+
$a .= $a = $a;
13+
}
14+
}
15+
test("");
16+
?>
17+
DONE
18+
--EXPECT--
19+
DONE

0 commit comments

Comments
 (0)