Skip to content

Commit 6446eaf

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Fix memory leak in array unpack with refcounted numeric string key
2 parents ccff3d9 + 260d2ac commit 6446eaf

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

Zend/tests/array_unpack/string_keys.phpt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ function gen() {
2222
}
2323
var_dump([...gen()]);
2424

25+
// Same as previous, but with refcounted string.
26+
function gen2() {
27+
$foo = "2";
28+
yield "4" . $foo => 42;
29+
}
30+
var_dump([...gen2()]);
31+
2532
?>
2633
--EXPECT--
2734
array(4) {
@@ -56,3 +63,7 @@ array(1) {
5663
[0]=>
5764
int(42)
5865
}
66+
array(1) {
67+
[0]=>
68+
int(42)
69+
}

Zend/zend_vm_def.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6069,6 +6069,7 @@ ZEND_VM_C_LABEL(add_unpack_again):
60696069
zend_hash_update(result_ht, Z_STR(key), val);
60706070
zval_ptr_dtor_str(&key);
60716071
} else {
6072+
zval_ptr_dtor(&key);
60726073
if (!zend_hash_next_index_insert(result_ht, val)) {
60736074
zend_cannot_add_element();
60746075
zval_ptr_dtor_nogc(val);

Zend/zend_vm_execute.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2609,6 +2609,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_UNPACK_SPEC_HANDLER(
26092609
zend_hash_update(result_ht, Z_STR(key), val);
26102610
zval_ptr_dtor_str(&key);
26112611
} else {
2612+
zval_ptr_dtor(&key);
26122613
if (!zend_hash_next_index_insert(result_ht, val)) {
26132614
zend_cannot_add_element();
26142615
zval_ptr_dtor_nogc(val);

0 commit comments

Comments
 (0)