Skip to content

Commit 260d2ac

Browse files
committed
Fix memory leak in array unpack with refcounted numeric string key
1 parent e7de9b2 commit 260d2ac

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
@@ -6060,6 +6060,7 @@ ZEND_VM_C_LABEL(add_unpack_again):
60606060
zend_hash_update(result_ht, Z_STR(key), val);
60616061
zval_ptr_dtor_str(&key);
60626062
} else {
6063+
zval_ptr_dtor(&key);
60636064
if (!zend_hash_next_index_insert(result_ht, val)) {
60646065
zend_cannot_add_element();
60656066
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)