libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit 3b0808ef21c6e380aef5eccf1608061a323d35fb
parent 901090b07ba9c89e086072b14768a24241f6714c
Author: Christian Grothoff <christian@grothoff.org>
Date:   Tue, 21 Jun 2011 22:04:16 +0000

race

Diffstat:
Msrc/daemon/connection.c | 6+++---
Msrc/daemon/daemon.c | 15++++++++++++++-
2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/src/daemon/connection.c b/src/daemon/connection.c @@ -2259,9 +2259,6 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) continue; case MHD_CONNECTION_CLOSED: daemon = connection->daemon; - DLL_remove (daemon->connections_head, - daemon->connections_tail, - connection); if (0 != pthread_mutex_lock(&daemon->cleanup_connection_mutex)) { #if HAVE_MESSAGES @@ -2269,6 +2266,9 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) #endif abort(); } + DLL_remove (daemon->connections_head, + daemon->connections_tail, + connection); DLL_insert (daemon->cleanup_head, daemon->cleanup_tail, connection); diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c @@ -1073,10 +1073,23 @@ MHD_add_connection (struct MHD_Daemon *daemon, return MHD_NO; } } - /* FIXME: race with removal operation! */ + if (0 != pthread_mutex_lock(&daemon->cleanup_connection_mutex)) + { +#if HAVE_MESSAGES + MHD_DLOG (daemon, "Failed to acquire cleanup mutex\n"); +#endif + abort(); + } DLL_insert (daemon->connections_head, daemon->connections_tail, connection); + if (0 != pthread_mutex_unlock(&daemon->cleanup_connection_mutex)) + { +#if HAVE_MESSAGES + MHD_DLOG (daemon, "Failed to release cleanup mutex\n"); +#endif + abort(); + } daemon->max_connections--; return MHD_YES; }