While the server uses fork() per connection (not threads), the _exit(0) in the signal handler is safe. However, the server_delete() call isn't async-signal-safe — it calls close(), SSL_CTX_free(), and free(), none of which are guaranteed to be safe inside a signal handler.
Location
src/server/server.c:115-123
Suggested Fix
Change the signal handler to only set a flag, and let the main loop check the flag:
Then in the accept loop, check g_shutdown_requested and break out to clean up properly.
Severity
Low
Category
Quality
## Description
In `src/server/server.c` lines 115-123, a global variable `g_server` is used for cleanup on signals:
```c
static Server* g_server = NULL;
static void cleanup(int sig) {
(void)sig;
if (g_server) {
server_delete(&g_server);
}
_exit(0);
}
```
While the server uses `fork()` per connection (not threads), the `_exit(0)` in the signal handler is safe. However, the `server_delete()` call isn't async-signal-safe — it calls `close()`, `SSL_CTX_free()`, and `free()`, none of which are guaranteed to be safe inside a signal handler.
## Location
`src/server/server.c:115-123`
## Suggested Fix
Change the signal handler to only set a flag, and let the main loop check the flag:
```c
static volatile sig_atomic_t g_shutdown_requested = 0;
static void cleanup(int sig) {
(void)sig;
g_shutdown_requested = 1;
}
```
Then in the accept loop, check `g_shutdown_requested` and break out to clean up properly.
## Severity
Low
## Category
Quality
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Description
In
src/server/server.clines 115-123, a global variableg_serveris used for cleanup on signals:While the server uses
fork()per connection (not threads), the_exit(0)in the signal handler is safe. However, theserver_delete()call isn't async-signal-safe — it callsclose(),SSL_CTX_free(), andfree(), none of which are guaranteed to be safe inside a signal handler.Location
src/server/server.c:115-123Suggested Fix
Change the signal handler to only set a flag, and let the main loop check the flag:
Then in the accept loop, check
g_shutdown_requestedand break out to clean up properly.Severity
Low
Category
Quality