commit 9b84b053cf67a5ced71ef1b1133ae65cbd0a6a16
parent 3b0808ef21c6e380aef5eccf1608061a323d35fb
Author: Christian Grothoff <christian@grothoff.org>
Date: Wed, 22 Jun 2011 08:08:07 +0000
must insert into DLL before creating thread
Diffstat:
1 file changed, 35 insertions(+), 17 deletions(-)
diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c
@@ -1054,6 +1054,24 @@ MHD_add_connection (struct MHD_Daemon *daemon,
}
#endif
+ 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();
+ }
+
/* attempt to create handler thread */
if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
{
@@ -1068,27 +1086,27 @@ MHD_add_connection (struct MHD_Daemon *daemon,
SHUTDOWN (client_socket, SHUT_RDWR);
CLOSE (client_socket);
MHD_ip_limit_del (daemon, addr, addrlen);
- free (connection->addr);
- free (connection);
- return MHD_NO;
- }
- }
- if (0 != pthread_mutex_lock(&daemon->cleanup_connection_mutex))
- {
+ if (0 != pthread_mutex_lock(&daemon->cleanup_connection_mutex))
+ {
#if HAVE_MESSAGES
- MHD_DLOG (daemon, "Failed to acquire cleanup mutex\n");
+ 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))
- {
+ abort();
+ }
+ DLL_remove (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");
+ MHD_DLOG (daemon, "Failed to release cleanup mutex\n");
#endif
- abort();
+ abort();
+ }
+ free (connection->addr);
+ free (connection);
+ return MHD_NO;
+ }
}
daemon->max_connections--;
return MHD_YES;