php-src/win32/signal.h
Niels Dossche fb3536fd60
Fix leak+crash with sapi_windows_set_ctrl_handler()
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.

Closes GH-18231.
2025-05-05 19:13:39 +02:00

16 lines
459 B
C

#ifndef PHP_WIN32_SIGNAL_H
#define PHP_WIN32_SIGNAL_H
#include <signal.h>
#include "win32/winutil.h"
#define SIGALRM 13
#define SIGVTALRM 26 /* virtual time alarm */
#define SIGPROF 27 /* profiling time alarm */
PHP_WINUTIL_API void php_win32_signal_ctrl_handler_init(void);
PHP_WINUTIL_API void php_win32_signal_ctrl_handler_request_shutdown(void);
PHP_WINUTIL_API void php_win32_signal_ctrl_handler_shutdown(void);
#endif /* PHP_WIN32_SIGNAL_H */