mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Fix GH-18322: SplObjectStorage debug handler mismanages memory
This commit is contained in:
commit
fc63a98f17
3 changed files with 33 additions and 4 deletions
4
NEWS
4
NEWS
|
@ -39,6 +39,10 @@ PHP NEWS
|
|||
(nielsdos)
|
||||
. Fix potential leaks when writing to BIO fails. (nielsdos)
|
||||
|
||||
- SPL:
|
||||
. Fixed bug GH-18322 (SplObjectStorage debug handler mismanages memory).
|
||||
(nielsdos)
|
||||
|
||||
- Standard:
|
||||
. Fixed bug GH-18145 (php8ts crashes in php_clear_stat_cache()).
|
||||
(Jakub Zelenka)
|
||||
|
|
|
@ -336,12 +336,10 @@ static inline HashTable* spl_object_storage_debug_info(zend_object *obj) /* {{{
|
|||
|
||||
ZEND_HASH_FOREACH_PTR(&intern->storage, element) {
|
||||
array_init(&tmp);
|
||||
/* Incrementing the refcount of obj and inf would confuse the garbage collector.
|
||||
* Prefer to null the destructor */
|
||||
Z_ARRVAL_P(&tmp)->pDestructor = NULL;
|
||||
zval obj;
|
||||
ZVAL_OBJ(&obj, element->obj);
|
||||
ZVAL_OBJ_COPY(&obj, element->obj);
|
||||
add_assoc_zval_ex(&tmp, "obj", sizeof("obj") - 1, &obj);
|
||||
Z_TRY_ADDREF(element->inf);
|
||||
add_assoc_zval_ex(&tmp, "inf", sizeof("inf") - 1, &element->inf);
|
||||
zend_hash_next_index_insert(Z_ARRVAL(storage), &tmp);
|
||||
} ZEND_HASH_FOREACH_END();
|
||||
|
|
27
ext/spl/tests/gh18322.phpt
Normal file
27
ext/spl/tests/gh18322.phpt
Normal file
|
@ -0,0 +1,27 @@
|
|||
--TEST--
|
||||
GH-18322 (SplObjectStorage debug handler mismanages memory)
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$stor = new SplObjectStorage();
|
||||
$obj = new stdClass;
|
||||
$stor[$obj] = 1;
|
||||
|
||||
$tmp = $stor->__debugInfo();
|
||||
$tmp2 = $tmp[array_key_first($tmp)];
|
||||
unset($tmp); // Drop $tmp2 RC to 1
|
||||
$tmp2[0]['obj'] = new stdClass;
|
||||
var_dump($tmp2);
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
array(1) {
|
||||
[0]=>
|
||||
array(2) {
|
||||
["obj"]=>
|
||||
object(stdClass)#3 (0) {
|
||||
}
|
||||
["inf"]=>
|
||||
int(1)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue