shutdown_hook()
shutdown_hook()
is a function that frees main memory before the server shuts down. It is responsible for freeing memory allocated by the server’s itself, such as the router, middleware, database, session manager, CORS handler, and others.
void shutdown_hook(void (*hook)(void));
Example usage:
void destroy_app(void){ close_db(); reset_sessions(); reset_router(); reset_cors();}
int main(void){ cors_t cors = { .origin = "*", .headers = "Content-Type, Authorization", .credentials = "true", };
init_cors(&cors); init_router(); init_sessions(); init_db();
shutdown_hook(destroy_app); ecewo(3000); return 0;}