[php-src] PR #18231: Fix leak+crash with sapi_windows_set_ctrl_handler()
| From: | nielsdos | Date: | Wed, 02 Apr 2025 18:20:39 +0000 |
| Subject: | [php-src] PR #18231: Fix leak+crash with sapi_windows_set_ctrl_handler() | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-31300@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/18231
Author: nielsdos
The ctrl_handler is never destroyed. We have to destroy it at request end so we avoid leaking it and
also avoid keeping a reference to previous request memory in a next request. The latter can result
in a crash and can be demonstrated with this script and
--repeat 2:
```php
class Test {
public function set() {
sapi_windows_set_ctrl_handler(self::cb(...));
}
public function cb() {
}
}
$test = new Test;
$test->set();
sleep(3);
```
When you hit CTRL+C in the second request you can crash.
This patch resolves both the leak and crash by destroying the ctrl_handler after a request.