diff --git a/lib/core-net/pollfd.c b/lib/core-net/pollfd.c index a8d8759d4..5a45ad724 100644 --- a/lib/core-net/pollfd.c +++ b/lib/core-net/pollfd.c @@ -372,7 +372,7 @@ __remove_wsi_socket_from_fds(struct lws *wsi) return -1; #endif - lws_same_vh_protocol_remove(wsi); + __lws_same_vh_protocol_remove(wsi); /* the guy who is to be deleted's slot index in pt->fds */ m = wsi->position_in_fds_table; diff --git a/lib/core-net/private-lib-core-net.h b/lib/core-net/private-lib-core-net.h index ebc1807b0..19c4d9a45 100644 --- a/lib/core-net/private-lib-core-net.h +++ b/lib/core-net/private-lib-core-net.h @@ -1388,7 +1388,7 @@ lws_async_dns_deinit(lws_async_dns_t *dns); int lws_protocol_init_vhost(struct lws_vhost *vh, int *any); int -_lws_generic_transaction_completed_active_conn(struct lws **wsi); +_lws_generic_transaction_completed_active_conn(struct lws **wsi, char take_vh_lock); #define ACTIVE_CONNS_SOLO 0 #define ACTIVE_CONNS_MUXED 1 diff --git a/lib/core-net/vhost.c b/lib/core-net/vhost.c index a80ef0a2b..ff73d0194 100644 --- a/lib/core-net/vhost.c +++ b/lib/core-net/vhost.c @@ -1506,7 +1506,7 @@ lws_vhost_active_conns(struct lws *wsi, struct lws **nwsi, const char *adsin) if (lwsi_state(w) == LRS_IDLING) { // lwsi_set_state(w, LRS_ESTABLISHED); - _lws_generic_transaction_completed_active_conn(&w); + _lws_generic_transaction_completed_active_conn(&w, 0); } //lwsi_set_state(w, LRS_H1C_ISSUE_HANDSHAKE2); @@ -1560,7 +1560,7 @@ lws_vhost_active_conns(struct lws *wsi, struct lws **nwsi, const char *adsin) if (lwsi_state(w) == LRS_IDLING) { // lwsi_set_state(w, LRS_ESTABLISHED); - _lws_generic_transaction_completed_active_conn(&w); + _lws_generic_transaction_completed_active_conn(&w, 0); } /* diff --git a/lib/core-net/wsi.c b/lib/core-net/wsi.c index d0b49af3e..0dfbdb995 100644 --- a/lib/core-net/wsi.c +++ b/lib/core-net/wsi.c @@ -761,7 +761,7 @@ lws_get_context(const struct lws *wsi) #if defined(LWS_WITH_CLIENT) int -_lws_generic_transaction_completed_active_conn(struct lws **_wsi) +_lws_generic_transaction_completed_active_conn(struct lws **_wsi, char take_vh_lock) { struct lws *wnew, *wsi = *_wsi; @@ -808,7 +808,8 @@ _lws_generic_transaction_completed_active_conn(struct lws **_wsi) * closing ourself */ - lws_vhost_lock(wsi->vhost); + if (take_vh_lock) + lws_vhost_lock(wsi->vhost); wnew = lws_container_of(wsi->dll2_cli_txn_queue_owner.head, struct lws, dll2_cli_txn_queue); @@ -891,7 +892,8 @@ _lws_generic_transaction_completed_active_conn(struct lws **_wsi) } lws_end_foreach_dll_safe(d, d1); - lws_vhost_unlock(wsi->vhost); + if (take_vh_lock) + lws_vhost_unlock(wsi->vhost); /* * The original leader who passed on all his powers already can die... diff --git a/lib/core/context.c b/lib/core/context.c index 8c357d7eb..4c2a48e7b 100644 --- a/lib/core/context.c +++ b/lib/core/context.c @@ -1075,6 +1075,10 @@ lws_context_destroy3(struct lws_context *context) lws_system_blob_destroy( lws_system_get_blob(context, n, 0)); +#if LWS_MAX_SMP > 1 + lws_mutex_refcount_destroy(&context->mr); +#endif + lws_free(context); lwsl_info("%s: ctx %p freed\n", __func__, context); @@ -1197,14 +1201,11 @@ lws_context_destroy2(struct lws_context *context) lws_check_deferred_free(context, 0, 1); #endif + lws_context_unlock(context); /* } context ------ */ -#if LWS_MAX_SMP > 1 - lws_mutex_refcount_destroy(&context->mr); -#endif #if defined(LWS_WITH_NETWORK) if (context->event_loop_ops->destroy_context2) if (context->event_loop_ops->destroy_context2(context)) { - lws_context_unlock(context); /* } context ----------- */ context->finalize_destroy_after_internal_loops_stopped = 1; return; } @@ -1216,12 +1217,10 @@ lws_context_destroy2(struct lws_context *context) for (n = 0; n < context->count_threads; n++) if (context->pt[n].inside_service) { lwsl_debug("%p: bailing as inside service\n", __func__); - lws_context_unlock(context); /* } context --- */ return; } } #endif - lws_context_unlock(context); /* } context ------------------- */ lws_context_destroy3(context); } diff --git a/lib/roles/http/client/client-http.c b/lib/roles/http/client/client-http.c index fd317c2dd..03af4f848 100644 --- a/lib/roles/http/client/client-http.c +++ b/lib/roles/http/client/client-http.c @@ -510,7 +510,7 @@ lws_http_transaction_completed_client(struct lws *wsi) * For h1, wsi may pass some assets on to a queued child and be * destroyed during this. */ - n = _lws_generic_transaction_completed_active_conn(&wsi); + n = _lws_generic_transaction_completed_active_conn(&wsi, 1); if (wsi->http.ah) { if (wsi->client_mux_substream)