[php-src] PR #22968: Free previous state when re-calling Reflection*::__construct()
| From: | iliaal | Date: | Fri, 31 Jul 2026 13:26:51 +0000 |
| Subject: | [php-src] PR #22968: Free previous state when re-calling Reflection*::__construct() | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-37409@lists.php.net to get a copy of this message | ||
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
```