Global g_server variable in server.c is not thread-safe for signal handling #66
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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