[php-src] PR #24177: Fix leak when the added previous exception is already in the chain
| From: | EdmondDantes | Date: | Wed, 07 Oct 2026 09:29:25 +0000 |
| Subject: | [php-src] PR #24177: Fix leak when the added previous exception is already in the chain | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-39235@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/24177
Author: EdmondDantes
zend_exception_set_previous() takes ownership of add_previous: every exit
either releases it or stores it as previous. When the walk over the exception's
previous chain reaches add_previous itself, the loop ends and the function
returns without releasing it. Pure PHP reaches it from finally:
```php
function f() {
$e = new RuntimeException("x");
try {
throw $e;
} finally {
throw new LogicException("y", 0, $e);
}
}
try { f(); } catch (Throwable $t) {}
```
A debug build reports Freeing ... (152 bytes), Total 1 memory leaks
detected on PHP-8.4 and master. The fix releases add_previous after the loop, as
the other discarding exit does.
Test: Zend/tests/try/try_finally_previous_already_in_chain.phpt, with the pending
exception as the direct previous and one level deeper.