diff options
Diffstat (limited to 'src/daemon/daemon.c')
-rw-r--r-- | src/daemon/daemon.c | 57 |
1 files changed, 27 insertions, 30 deletions
diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c index a2dbba0e..22d53a2d 100644 --- a/src/daemon/daemon.c +++ b/src/daemon/daemon.c | |||
@@ -1993,12 +1993,14 @@ MHD_start_daemon_va (unsigned int options, | |||
1993 | return NULL; | 1993 | return NULL; |
1994 | } | 1994 | } |
1995 | } | 1995 | } |
1996 | |||
1996 | if (0 != pthread_mutex_init (&retVal->nnc_lock, NULL)) | 1997 | if (0 != pthread_mutex_init (&retVal->nnc_lock, NULL)) |
1997 | { | 1998 | { |
1998 | #if HAVE_MESSAGES | 1999 | #if HAVE_MESSAGES |
1999 | MHD_DLOG (retVal, | 2000 | MHD_DLOG (retVal, |
2000 | "MHD failed to initialize nonce-nc mutex\n"); | 2001 | "MHD failed to initialize nonce-nc mutex\n"); |
2001 | #endif | 2002 | #endif |
2003 | free (retVal->nnc); | ||
2002 | free (retVal); | 2004 | free (retVal); |
2003 | return NULL; | 2005 | return NULL; |
2004 | } | 2006 | } |
@@ -2012,8 +2014,7 @@ MHD_start_daemon_va (unsigned int options, | |||
2012 | MHD_DLOG (retVal, | 2014 | MHD_DLOG (retVal, |
2013 | "MHD thread pooling only works with MHD_USE_SELECT_INTERNALLY\n"); | 2015 | "MHD thread pooling only works with MHD_USE_SELECT_INTERNALLY\n"); |
2014 | #endif | 2016 | #endif |
2015 | free (retVal); | 2017 | goto free_and_fail; |
2016 | return NULL; | ||
2017 | } | 2018 | } |
2018 | 2019 | ||
2019 | #ifdef __SYMBIAN32__ | 2020 | #ifdef __SYMBIAN32__ |
@@ -2023,8 +2024,7 @@ MHD_start_daemon_va (unsigned int options, | |||
2023 | MHD_DLOG (retVal, | 2024 | MHD_DLOG (retVal, |
2024 | "Threaded operations are not supported on Symbian.\n"); | 2025 | "Threaded operations are not supported on Symbian.\n"); |
2025 | #endif | 2026 | #endif |
2026 | free (retVal); | 2027 | goto free_and_fail; |
2027 | return NULL; | ||
2028 | } | 2028 | } |
2029 | #endif | 2029 | #endif |
2030 | if (retVal->socket_fd == -1) | 2030 | if (retVal->socket_fd == -1) |
@@ -2038,8 +2038,7 @@ MHD_start_daemon_va (unsigned int options, | |||
2038 | MHD_DLOG (retVal, | 2038 | MHD_DLOG (retVal, |
2039 | "AF_INET6 not supported\n"); | 2039 | "AF_INET6 not supported\n"); |
2040 | #endif | 2040 | #endif |
2041 | free (retVal); | 2041 | goto free_and_fail; |
2042 | return NULL; | ||
2043 | } | 2042 | } |
2044 | #endif | 2043 | #endif |
2045 | else | 2044 | else |
@@ -2052,8 +2051,7 @@ MHD_start_daemon_va (unsigned int options, | |||
2052 | "Call to socket failed: %s\n", | 2051 | "Call to socket failed: %s\n", |
2053 | STRERROR (errno)); | 2052 | STRERROR (errno)); |
2054 | #endif | 2053 | #endif |
2055 | free (retVal); | 2054 | goto free_and_fail; |
2056 | return NULL; | ||
2057 | } | 2055 | } |
2058 | if ((SETSOCKOPT (socket_fd, | 2056 | if ((SETSOCKOPT (socket_fd, |
2059 | SOL_SOCKET, | 2057 | SOL_SOCKET, |
@@ -2127,8 +2125,7 @@ MHD_start_daemon_va (unsigned int options, | |||
2127 | STRERROR (errno)); | 2125 | STRERROR (errno)); |
2128 | #endif | 2126 | #endif |
2129 | CLOSE (socket_fd); | 2127 | CLOSE (socket_fd); |
2130 | free (retVal); | 2128 | goto free_and_fail; |
2131 | return NULL; | ||
2132 | } | 2129 | } |
2133 | 2130 | ||
2134 | if (LISTEN (socket_fd, 20) < 0) | 2131 | if (LISTEN (socket_fd, 20) < 0) |
@@ -2140,8 +2137,7 @@ MHD_start_daemon_va (unsigned int options, | |||
2140 | STRERROR (errno)); | 2137 | STRERROR (errno)); |
2141 | #endif | 2138 | #endif |
2142 | CLOSE (socket_fd); | 2139 | CLOSE (socket_fd); |
2143 | free (retVal); | 2140 | goto free_and_fail; |
2144 | return NULL; | ||
2145 | } | 2141 | } |
2146 | } | 2142 | } |
2147 | else | 2143 | else |
@@ -2160,8 +2156,7 @@ MHD_start_daemon_va (unsigned int options, | |||
2160 | FD_SETSIZE); | 2156 | FD_SETSIZE); |
2161 | #endif | 2157 | #endif |
2162 | CLOSE (socket_fd); | 2158 | CLOSE (socket_fd); |
2163 | free (retVal); | 2159 | goto free_and_fail; |
2164 | return NULL; | ||
2165 | } | 2160 | } |
2166 | #endif | 2161 | #endif |
2167 | 2162 | ||
@@ -2172,8 +2167,7 @@ MHD_start_daemon_va (unsigned int options, | |||
2172 | "MHD failed to initialize IP connection limit mutex\n"); | 2167 | "MHD failed to initialize IP connection limit mutex\n"); |
2173 | #endif | 2168 | #endif |
2174 | CLOSE (socket_fd); | 2169 | CLOSE (socket_fd); |
2175 | free (retVal); | 2170 | goto free_and_fail; |
2176 | return NULL; | ||
2177 | } | 2171 | } |
2178 | 2172 | ||
2179 | #if HTTPS_SUPPORT | 2173 | #if HTTPS_SUPPORT |
@@ -2185,13 +2179,8 @@ MHD_start_daemon_va (unsigned int options, | |||
2185 | "Failed to initialize TLS support\n"); | 2179 | "Failed to initialize TLS support\n"); |
2186 | #endif | 2180 | #endif |
2187 | CLOSE (socket_fd); | 2181 | CLOSE (socket_fd); |
2188 | #ifdef DAUTH_SUPPORT | ||
2189 | pthread_mutex_destroy (&retVal->nnc_lock); | ||
2190 | free (retVal->nnc); | ||
2191 | #endif | ||
2192 | pthread_mutex_destroy (&retVal->per_ip_connection_mutex); | 2182 | pthread_mutex_destroy (&retVal->per_ip_connection_mutex); |
2193 | free (retVal); | 2183 | goto free_and_fail; |
2194 | return NULL; | ||
2195 | } | 2184 | } |
2196 | #endif | 2185 | #endif |
2197 | if ( ( (0 != (options & MHD_USE_THREAD_PER_CONNECTION)) || | 2186 | if ( ( (0 != (options & MHD_USE_THREAD_PER_CONNECTION)) || |
@@ -2205,14 +2194,9 @@ MHD_start_daemon_va (unsigned int options, | |||
2205 | "Failed to create listen thread: %s\n", | 2194 | "Failed to create listen thread: %s\n", |
2206 | STRERROR (res_thread_create)); | 2195 | STRERROR (res_thread_create)); |
2207 | #endif | 2196 | #endif |
2208 | #ifdef DAUTH_SUPPORT | ||
2209 | pthread_mutex_destroy (&retVal->nnc_lock); | ||
2210 | free (retVal->nnc); | ||
2211 | #endif | ||
2212 | pthread_mutex_destroy (&retVal->per_ip_connection_mutex); | 2197 | pthread_mutex_destroy (&retVal->per_ip_connection_mutex); |
2213 | free (retVal); | ||
2214 | CLOSE (socket_fd); | 2198 | CLOSE (socket_fd); |
2215 | return NULL; | 2199 | goto free_and_fail; |
2216 | } | 2200 | } |
2217 | if (retVal->worker_pool_size > 0) | 2201 | if (retVal->worker_pool_size > 0) |
2218 | { | 2202 | { |
@@ -2306,8 +2290,7 @@ thread_failed: | |||
2306 | pthread_mutex_destroy (&retVal->per_ip_connection_mutex); | 2290 | pthread_mutex_destroy (&retVal->per_ip_connection_mutex); |
2307 | if (NULL != retVal->worker_pool) | 2291 | if (NULL != retVal->worker_pool) |
2308 | free (retVal->worker_pool); | 2292 | free (retVal->worker_pool); |
2309 | free (retVal); | 2293 | goto free_and_fail; |
2310 | return NULL; | ||
2311 | } | 2294 | } |
2312 | 2295 | ||
2313 | /* Shutdown worker threads we've already created. Pretend | 2296 | /* Shutdown worker threads we've already created. Pretend |
@@ -2317,11 +2300,23 @@ thread_failed: | |||
2317 | retVal->worker_pool_size = i - 1; | 2300 | retVal->worker_pool_size = i - 1; |
2318 | MHD_stop_daemon (retVal); | 2301 | MHD_stop_daemon (retVal); |
2319 | return NULL; | 2302 | return NULL; |
2303 | |||
2304 | free_and_fail: | ||
2305 | /* clean up basic memory state in 'retVal' and return NULL to | ||
2306 | indicate failure */ | ||
2307 | #ifdef DAUTH_SUPPORT | ||
2308 | free (retVal->nnc); | ||
2309 | pthread_mutex_destroy (&retVal->nnc_lock); | ||
2310 | #endif | ||
2311 | free (retVal); | ||
2312 | return NULL; | ||
2320 | } | 2313 | } |
2321 | 2314 | ||
2322 | 2315 | ||
2323 | /** | 2316 | /** |
2324 | * Close all connections for the daemon | 2317 | * Close all connections for the daemon |
2318 | * | ||
2319 | * @param daemon daemon to close down | ||
2325 | */ | 2320 | */ |
2326 | static void | 2321 | static void |
2327 | MHD_close_connections (struct MHD_Daemon *daemon) | 2322 | MHD_close_connections (struct MHD_Daemon *daemon) |
@@ -2345,6 +2340,8 @@ MHD_close_connections (struct MHD_Daemon *daemon) | |||
2345 | 2340 | ||
2346 | /** | 2341 | /** |
2347 | * Shutdown an http daemon | 2342 | * Shutdown an http daemon |
2343 | * | ||
2344 | * @param daemon daemon to stop | ||
2348 | */ | 2345 | */ |
2349 | void | 2346 | void |
2350 | MHD_stop_daemon (struct MHD_Daemon *daemon) | 2347 | MHD_stop_daemon (struct MHD_Daemon *daemon) |