Skip to content

Commit 61b432c

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: JIT: Fixed memory leak
2 parents baac970 + fac78ee commit 61b432c

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

ext/opcache/jit/zend_jit_arm64.dasc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4951,6 +4951,8 @@ static int zend_jit_concat_helper(dasm_State **Dst,
49514951
}
49524952
| LOAD_ZVAL_ADDR FCARG2x, op2_addr
49534953
| EXT_CALL zend_jit_fast_assign_concat_helper, REG0
4954+
/* concatination with itself may reduce refcount */
4955+
op2_info |= MAY_BE_RC1;
49544956
} else {
49554957
if (Z_REG(res_addr) != ZREG_FCARG1 || Z_OFFSET(res_addr) != 0) {
49564958
| LOAD_ZVAL_ADDR FCARG1x, res_addr

ext/opcache/jit/zend_jit_helpers.c

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

11631163
do {
11641164
if (Z_REFCOUNTED_P(op1)) {
1165-
if (GC_REFCOUNT(Z_STR_P(op1)) == 1) {
1165+
if (GC_REFCOUNT(Z_STR_P(op1)) == 1 && EXPECTED(Z_STR_P(op1) != Z_STR_P(op2))) {
11661166
result_str = perealloc(Z_STR_P(op1), ZEND_MM_ALIGNED_SIZE(_ZSTR_STRUCT_SIZE(result_len)), 0);
11671167
ZSTR_LEN(result_str) = result_len;
11681168
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
@@ -5397,6 +5397,8 @@ static int zend_jit_concat_helper(dasm_State **Dst,
53975397
}
53985398
| LOAD_ZVAL_ADDR FCARG2a, op2_addr
53995399
| EXT_CALL zend_jit_fast_assign_concat_helper, r0
5400+
/* concatination with itself may reduce refcount */
5401+
op2_info |= MAY_BE_RC1;
54005402
} else {
54015403
if (Z_REG(res_addr) != ZREG_FCARG1 || Z_OFFSET(res_addr) != 0) {
54025404
| 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)