[GIT-PULLS] [php-src] PR #22968: Free previous state when re-calling Reflection*::__construct()
[email protected] (iliaal) Fri, 31 Jul 2026 13:26:51 +0000
| Newsgroups | php.git-pulls |
|---|---|
| Message-ID | <[email protected]> |
Pull Request: https://github.com/php/php-src/pull/22968
Author: iliaal
`ReflectionMethod::__construct()` overwrites intern->ptr without releasing the previous value. When the reflected method is Closure::__invoke() that value is a trampoline allocated by `zend_get_closure_invoke_method()`, so every re-construct leaks one. ReflectionClassConstant::__construct() has the same shape for the $name and $class property slots and leaks a string reference whenever the constant name is not interned. ReflectionFunction, ReflectionParameter and ReflectionProperty already release prior state on re-entry.
```php
$r = new ReflectionMethod(function () {}, '__invoke');
for ($i = 0; $i < 10000; $i++) {
$r->__construct(function () {}, '__invoke');
}
// 2.5 MB of growth on PHP-8.4, zero with the patch
```