[php-src] PR #25365: Fix memory leak in filter_var_array() when a nested element throws
| From: | eyupcanakman | Date: | Tue, 10 Nov 2026 09:52:32 +0000 |
| Subject: | [php-src] PR #25365: Fix memory leak in filter_var_array() when a nested element throws | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-40500@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/25365
Author: eyupcanakman
php_filter_array_handler() filters a copy of each input value, nval, and
returns as soon as an exception is pending. It never frees that copy, so an array value leaks.
```php
filter_var_array(['a' => ['1', 'x']], ['a' =>
['filter' => FILTER_VALIDATE_INT, 'flags' => FILTER_REQUIRE_ARRAY |
FILTER_THROW_ON_FAILURE]]);
```
On a debug build the exception is followed by === Total 2 memory leaks detected ===.
A FILTER_CALLBACK callback that throws on a nested element leaks the same way, and so
does filter_input_array(), which uses the same handler. The early return came in with
FILTER_THROW_ON_FAILURE, so PHP-8.4 does not have it and does not leak. GH-25349 adds
the return to 8.4 with the copy already freed.