From d5d2bbc4dbbd1440f5958a8c704e1002c72e7b0b Mon Sep 17 00:00:00 2001 From: Andy Green Date: Thu, 21 Mar 2019 13:41:36 +0800 Subject: [PATCH] hrtimer: remove from correct dll before resetting --- lib/core-net/close.c | 16 ++++++++++------ lib/core-net/wsi-timeout.c | 3 +-- lib/roles/listen/ops-listen.c | 5 ++++- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/core-net/close.c b/lib/core-net/close.c index b72b98a78..f58969eb6 100644 --- a/lib/core-net/close.c +++ b/lib/core-net/close.c @@ -153,15 +153,17 @@ __lws_close_free_wsi(struct lws *wsi, enum lws_close_status reason, #if !defined(LWS_NO_CLIENT) lws_free_set_NULL(wsi->cli_hostname_copy); - /* we are no longer an active client connection that can piggyback */ - lws_dll_remove_track_tail(&wsi->dll_cli_active_conns, - &wsi->vhost->dll_cli_active_conns_head); /* * if we have wsi in our transaction queue, if we are closing we * must go through and close all those first */ if (wsi->vhost) { + + /* we are no longer an active client connection that can piggyback */ + lws_dll_remove_track_tail(&wsi->dll_cli_active_conns, + &wsi->vhost->dll_cli_active_conns_head); + if ((int)reason != -1) lws_vhost_lock(wsi->vhost); @@ -201,7 +203,8 @@ __lws_close_free_wsi(struct lws *wsi, enum lws_close_status reason, if (wsi->role_ops == &role_ops_raw_file) { lws_remove_child_from_any_parent(wsi); __remove_wsi_socket_from_fds(wsi); - wsi->protocol->callback(wsi, wsi->role_ops->close_cb[0], + if (wsi->protocol) + wsi->protocol->callback(wsi, wsi->role_ops->close_cb[0], wsi->user_space, NULL, 0); goto async_close; } @@ -329,7 +332,7 @@ just_kill_connection: n = 0; if (!wsi->told_user_closed && wsi->user_space && - wsi->protocol_bind_balance) { + wsi->protocol_bind_balance && wsi->protocol) { lwsl_debug("%s: %p: DROP_PROTOCOL %s\n", __func__, wsi, wsi->protocol->name); wsi->protocol->callback(wsi, @@ -340,7 +343,8 @@ just_kill_connection: } if ((lwsi_state(wsi) == LRS_WAITING_SERVER_REPLY || - lwsi_state(wsi) == LRS_WAITING_CONNECT) && !wsi->already_did_cce) + lwsi_state(wsi) == LRS_WAITING_CONNECT) && + !wsi->already_did_cce && wsi->protocol) wsi->protocol->callback(wsi, LWS_CALLBACK_CLIENT_CONNECTION_ERROR, wsi->user_space, NULL, 0); diff --git a/lib/core-net/wsi-timeout.c b/lib/core-net/wsi-timeout.c index cc72368f7..6e2d10bb4 100644 --- a/lib/core-net/wsi-timeout.c +++ b/lib/core-net/wsi-timeout.c @@ -21,7 +21,6 @@ #include "core/private.h" - void __lws_remove_from_timeout_list(struct lws *wsi) { @@ -50,7 +49,7 @@ __lws_set_timer_usecs(struct lws *wsi, lws_usec_t usecs) struct lws *wsi1; int bef = 0; - __lws_remove_from_timeout_list(wsi); + lws_dll_remove_track_tail(&wsi->dll_hrtimer, &pt->dll_hrtimer_head); if (usecs == LWS_SET_TIMER_USEC_CANCEL) return; diff --git a/lib/roles/listen/ops-listen.c b/lib/roles/listen/ops-listen.c index 67234f807..e0115ea71 100644 --- a/lib/roles/listen/ops-listen.c +++ b/lib/roles/listen/ops-listen.c @@ -92,8 +92,10 @@ rops_handle_POLLIN_listen(struct lws_context_per_thread *pt, struct lws *wsi, return LWS_HPI_RET_HANDLED; } - if (context->being_destroyed) + if (context->being_destroyed) { + compatible_close(accept_fd); return LWS_HPI_RET_PLEASE_CLOSE_ME; + } lws_plat_set_socket_options(wsi->vhost, accept_fd, 0); @@ -120,6 +122,7 @@ rops_handle_POLLIN_listen(struct lws_context_per_thread *pt, struct lws *wsi, NULL, (void *)(lws_intptr_t)accept_fd, 0)) { lwsl_debug("Callback denied net connection\n"); + compatible_close(accept_fd); return LWS_HPI_RET_PLEASE_CLOSE_ME; }