aboutsummaryrefslogtreecommitdiff
path: root/src/lib/connection_cleanup.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/connection_cleanup.c')
-rw-r--r--src/lib/connection_cleanup.c132
1 files changed, 66 insertions, 66 deletions
diff --git a/src/lib/connection_cleanup.c b/src/lib/connection_cleanup.c
index 8883213b..4f2cfb0f 100644
--- a/src/lib/connection_cleanup.c
+++ b/src/lib/connection_cleanup.c
@@ -49,7 +49,7 @@ connection_cleanup_upgraded (struct MHD_Connection *connection)
49 49
50 if (NULL != (tls = connection->daemon->tls_api)) 50 if (NULL != (tls = connection->daemon->tls_api))
51 (void) tls->shutdown_connection (tls->cls, 51 (void) tls->shutdown_connection (tls->cls,
52 connection->tls_cs); 52 connection->tls_cs);
53 } 53 }
54 if (MHD_INVALID_SOCKET != urh->mhd.socket) 54 if (MHD_INVALID_SOCKET != urh->mhd.socket)
55 MHD_socket_close_chk_ (urh->mhd.socket); 55 MHD_socket_close_chk_ (urh->mhd.socket);
@@ -65,7 +65,7 @@ connection_cleanup_upgraded (struct MHD_Connection *connection)
65/** 65/**
66 * Free resources associated with all closed connections. (destroy 66 * Free resources associated with all closed connections. (destroy
67 * responses, free buffers, etc.). All closed connections are kept in 67 * responses, free buffers, etc.). All closed connections are kept in
68 * the "cleanup" doubly-linked list. 68 * the "cleanup" doubly-linked list.
69 * 69 *
70 * @remark To be called only from thread that process daemon's 70 * @remark To be called only from thread that process daemon's
71 * select()/poll()/etc. 71 * select()/poll()/etc.
@@ -79,79 +79,79 @@ MHD_connection_cleanup_ (struct MHD_Daemon *daemon)
79 79
80 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); 80 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
81 while (NULL != (pos = daemon->cleanup_tail)) 81 while (NULL != (pos = daemon->cleanup_tail))
82 { 82 {
83 DLL_remove (daemon->cleanup_head, 83 DLL_remove (daemon->cleanup_head,
84 daemon->cleanup_tail, 84 daemon->cleanup_tail,
85 pos); 85 pos);
86 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); 86 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
87 87
88 if ( (MHD_TM_THREAD_PER_CONNECTION == daemon->threading_mode) && 88 if ( (MHD_TM_THREAD_PER_CONNECTION == daemon->threading_mode) &&
89 (! pos->thread_joined) && 89 (! pos->thread_joined) &&
90 (! MHD_join_thread_ (pos->pid.handle)) ) 90 (! MHD_join_thread_ (pos->pid.handle)) )
91 MHD_PANIC (_("Failed to join a thread\n")); 91 MHD_PANIC (_ ("Failed to join a thread\n"));
92#ifdef UPGRADE_SUPPORT 92#ifdef UPGRADE_SUPPORT
93 connection_cleanup_upgraded (pos); 93 connection_cleanup_upgraded (pos);
94#endif /* UPGRADE_SUPPORT */ 94#endif /* UPGRADE_SUPPORT */
95 MHD_pool_destroy (pos->pool); 95 MHD_pool_destroy (pos->pool);
96#ifdef HTTPS_SUPPORT 96#ifdef HTTPS_SUPPORT
97 { 97 {
98 struct MHD_TLS_Plugin *tls; 98 struct MHD_TLS_Plugin *tls;
99 99
100 if (NULL != (tls = daemon->tls_api)) 100 if (NULL != (tls = daemon->tls_api))
101 tls->teardown_connection (tls->cls, 101 tls->teardown_connection (tls->cls,
102 pos->tls_cs); 102 pos->tls_cs);
103 } 103 }
104#endif /* HTTPS_SUPPORT */ 104#endif /* HTTPS_SUPPORT */
105 105
106 /* clean up the connection */ 106 /* clean up the connection */
107 if (NULL != daemon->notify_connection_cb) 107 if (NULL != daemon->notify_connection_cb)
108 daemon->notify_connection_cb (daemon->notify_connection_cb_cls, 108 daemon->notify_connection_cb (daemon->notify_connection_cb_cls,
109 pos, 109 pos,
110 MHD_CONNECTION_NOTIFY_CLOSED); 110 MHD_CONNECTION_NOTIFY_CLOSED);
111 MHD_ip_limit_del (daemon, 111 MHD_ip_limit_del (daemon,
112 (const struct sockaddr *) &pos->addr, 112 (const struct sockaddr *) &pos->addr,
113 pos->addr_len); 113 pos->addr_len);
114#ifdef EPOLL_SUPPORT 114#ifdef EPOLL_SUPPORT
115 if (MHD_ELS_EPOLL == daemon->event_loop_syscall) 115 if (MHD_ELS_EPOLL == daemon->event_loop_syscall)
116 { 116 {
117 if (0 != (pos->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL)) 117 if (0 != (pos->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL))
118 { 118 {
119 EDLL_remove (daemon->eready_head, 119 EDLL_remove (daemon->eready_head,
120 daemon->eready_tail, 120 daemon->eready_tail,
121 pos); 121 pos);
122 pos->epoll_state &= ~MHD_EPOLL_STATE_IN_EREADY_EDLL; 122 pos->epoll_state &= ~MHD_EPOLL_STATE_IN_EREADY_EDLL;
123 } 123 }
124 if ( (-1 != daemon->epoll_fd) && 124 if ( (-1 != daemon->epoll_fd) &&
125 (0 != (pos->epoll_state & MHD_EPOLL_STATE_IN_EPOLL_SET)) ) 125 (0 != (pos->epoll_state & MHD_EPOLL_STATE_IN_EPOLL_SET)) )
126 { 126 {
127 /* epoll documentation suggests that closing a FD 127 /* epoll documentation suggests that closing a FD
128 automatically removes it from the epoll set; however, 128 automatically removes it from the epoll set; however,
129 this is not true as if we fail to do manually remove it, 129 this is not true as if we fail to do manually remove it,
130 we are still seeing an event for this fd in epoll, 130 we are still seeing an event for this fd in epoll,
131 causing grief (use-after-free...) --- at least on my 131 causing grief (use-after-free...) --- at least on my
132 system. */ 132 system. */
133 if (0 != epoll_ctl (daemon->epoll_fd, 133 if (0 != epoll_ctl (daemon->epoll_fd,
134 EPOLL_CTL_DEL, 134 EPOLL_CTL_DEL,
135 pos->socket_fd, 135 pos->socket_fd,
136 NULL)) 136 NULL))
137 MHD_PANIC (_("Failed to remove FD from epoll set\n")); 137 MHD_PANIC (_ ("Failed to remove FD from epoll set\n"));
138 pos->epoll_state &= ~MHD_EPOLL_STATE_IN_EPOLL_SET; 138 pos->epoll_state &= ~MHD_EPOLL_STATE_IN_EPOLL_SET;
139 } 139 }
140 } 140 }
141#endif 141#endif
142 if (NULL != pos->request.response) 142 if (NULL != pos->request.response)
143 { 143 {
144 MHD_response_queue_for_destroy (pos->request.response); 144 MHD_response_queue_for_destroy (pos->request.response);
145 pos->request.response = NULL; 145 pos->request.response = NULL;
146 }
147 if (MHD_INVALID_SOCKET != pos->socket_fd)
148 MHD_socket_close_chk_ (pos->socket_fd);
149 free (pos);
150
151 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
152 daemon->connections--;
153 daemon->at_limit = false;
154 } 146 }
147 if (MHD_INVALID_SOCKET != pos->socket_fd)
148 MHD_socket_close_chk_ (pos->socket_fd);
149 free (pos);
150
151 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
152 daemon->connections--;
153 daemon->at_limit = false;
154 }
155 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); 155 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
156} 156}
157 157