Fix memory leak in array unpack with refcounted numeric string key

This commit is contained in:
Nikita Popov 2021-09-14 12:14:12 +02:00
parent e7de9b2091
commit 260d2acdb4
3 changed files with 13 additions and 0 deletions

View File

@ -22,6 +22,13 @@ function gen() {
}
var_dump([...gen()]);
// Same as previous, but with refcounted string.
function gen2() {
$foo = "2";
yield "4" . $foo => 42;
}
var_dump([...gen2()]);
?>
--EXPECT--
array(4) {
@ -56,3 +63,7 @@ array(1) {
[0]=>
int(42)
}
array(1) {
[0]=>
int(42)
}

View File

@ -6060,6 +6060,7 @@ ZEND_VM_C_LABEL(add_unpack_again):
zend_hash_update(result_ht, Z_STR(key), val);
zval_ptr_dtor_str(&key);
} else {
zval_ptr_dtor(&key);
if (!zend_hash_next_index_insert(result_ht, val)) {
zend_cannot_add_element();
zval_ptr_dtor_nogc(val);

View File

@ -2609,6 +2609,7 @@ add_unpack_again:
zend_hash_update(result_ht, Z_STR(key), val);
zval_ptr_dtor_str(&key);
} else {
zval_ptr_dtor(&key);
if (!zend_hash_next_index_insert(result_ht, val)) {
zend_cannot_add_element();
zval_ptr_dtor_nogc(val);