diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-06-22 08:08:07 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-06-22 08:08:07 +0000 |
commit | 9b84b053cf67a5ced71ef1b1133ae65cbd0a6a16 (patch) | |
tree | 0f2f1af093d57f0fa9c561db1edbff09dc9d94be | |
parent | 3b0808ef21c6e380aef5eccf1608061a323d35fb (diff) | |
download | libmicrohttpd-9b84b053cf67a5ced71ef1b1133ae65cbd0a6a16.tar.gz libmicrohttpd-9b84b053cf67a5ced71ef1b1133ae65cbd0a6a16.zip |
must insert into DLL before creating thread
-rw-r--r-- | src/daemon/daemon.c | 52 |
1 files changed, 35 insertions, 17 deletions
diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c index 71d069ec..f4273453 100644 --- a/src/daemon/daemon.c +++ b/src/daemon/daemon.c | |||
@@ -1054,6 +1054,24 @@ MHD_add_connection (struct MHD_Daemon *daemon, | |||
1054 | } | 1054 | } |
1055 | #endif | 1055 | #endif |
1056 | 1056 | ||
1057 | if (0 != pthread_mutex_lock(&daemon->cleanup_connection_mutex)) | ||
1058 | { | ||
1059 | #if HAVE_MESSAGES | ||
1060 | MHD_DLOG (daemon, "Failed to acquire cleanup mutex\n"); | ||
1061 | #endif | ||
1062 | abort(); | ||
1063 | } | ||
1064 | DLL_insert (daemon->connections_head, | ||
1065 | daemon->connections_tail, | ||
1066 | connection); | ||
1067 | if (0 != pthread_mutex_unlock(&daemon->cleanup_connection_mutex)) | ||
1068 | { | ||
1069 | #if HAVE_MESSAGES | ||
1070 | MHD_DLOG (daemon, "Failed to release cleanup mutex\n"); | ||
1071 | #endif | ||
1072 | abort(); | ||
1073 | } | ||
1074 | |||
1057 | /* attempt to create handler thread */ | 1075 | /* attempt to create handler thread */ |
1058 | if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) | 1076 | if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) |
1059 | { | 1077 | { |
@@ -1068,27 +1086,27 @@ MHD_add_connection (struct MHD_Daemon *daemon, | |||
1068 | SHUTDOWN (client_socket, SHUT_RDWR); | 1086 | SHUTDOWN (client_socket, SHUT_RDWR); |
1069 | CLOSE (client_socket); | 1087 | CLOSE (client_socket); |
1070 | MHD_ip_limit_del (daemon, addr, addrlen); | 1088 | MHD_ip_limit_del (daemon, addr, addrlen); |
1071 | free (connection->addr); | 1089 | if (0 != pthread_mutex_lock(&daemon->cleanup_connection_mutex)) |
1072 | free (connection); | 1090 | { |
1073 | return MHD_NO; | ||
1074 | } | ||
1075 | } | ||
1076 | if (0 != pthread_mutex_lock(&daemon->cleanup_connection_mutex)) | ||
1077 | { | ||
1078 | #if HAVE_MESSAGES | 1091 | #if HAVE_MESSAGES |
1079 | MHD_DLOG (daemon, "Failed to acquire cleanup mutex\n"); | 1092 | MHD_DLOG (daemon, "Failed to acquire cleanup mutex\n"); |
1080 | #endif | 1093 | #endif |
1081 | abort(); | 1094 | abort(); |
1082 | } | 1095 | } |
1083 | DLL_insert (daemon->connections_head, | 1096 | DLL_remove (daemon->connections_head, |
1084 | daemon->connections_tail, | 1097 | daemon->connections_tail, |
1085 | connection); | 1098 | connection); |
1086 | if (0 != pthread_mutex_unlock(&daemon->cleanup_connection_mutex)) | 1099 | if (0 != pthread_mutex_unlock(&daemon->cleanup_connection_mutex)) |
1087 | { | 1100 | { |
1088 | #if HAVE_MESSAGES | 1101 | #if HAVE_MESSAGES |
1089 | MHD_DLOG (daemon, "Failed to release cleanup mutex\n"); | 1102 | MHD_DLOG (daemon, "Failed to release cleanup mutex\n"); |
1090 | #endif | 1103 | #endif |
1091 | abort(); | 1104 | abort(); |
1105 | } | ||
1106 | free (connection->addr); | ||
1107 | free (connection); | ||
1108 | return MHD_NO; | ||
1109 | } | ||
1092 | } | 1110 | } |
1093 | daemon->max_connections--; | 1111 | daemon->max_connections--; |
1094 | return MHD_YES; | 1112 | return MHD_YES; |