mirror of
https://github.com/php/php-src.git
synced 2026-10-29 02:07:35 +08:00
ReflectionMethod::__construct() overwrote intern->ptr without releasing the previous Closure::__invoke() trampoline, and ReflectionClassConstant::__construct() overwrote the $name and $class slots without dropping their previous references. ReflectionFunction, ReflectionParameter and ReflectionProperty already release prior state on re-entry. Closes GH-22968
34 lines
629 B
PHP
34 lines
629 B
PHP
--TEST--
|
|
ReflectionClassConstant double construct call does not leak $name and $class
|
|
--FILE--
|
|
<?php
|
|
|
|
class C {
|
|
const FOO = 1;
|
|
}
|
|
|
|
function test(ReflectionClassConstant $r) {
|
|
/* implode() so that the name is not an interned string. */
|
|
$r->__construct(C::class, implode('', ['F', 'O', 'O']));
|
|
}
|
|
|
|
$r = new ReflectionClassConstant(C::class, 'FOO');
|
|
for ($i = 0; $i < 10; $i++) {
|
|
test($r);
|
|
}
|
|
|
|
$before = memory_get_usage();
|
|
for ($i = 0; $i < 1000; $i++) {
|
|
test($r);
|
|
}
|
|
$after = memory_get_usage();
|
|
|
|
var_dump($before === $after);
|
|
var_dump($r->name, $r->class);
|
|
|
|
?>
|
|
--EXPECT--
|
|
bool(true)
|
|
string(3) "FOO"
|
|
string(1) "C"
|