Skip to content

Commit ca49e74

Browse files
committed
vhost: track vh-protocol protocol init
We may paint vhosts with plugin protocols, but that doesn't mean that the protocol is enabled on the vhost. In turn that means if we didn't do PROTOCOL_INIT, we should not do PROTOCOL_DESTROY on the vhost-protocol combo.
1 parent 70dd4a6 commit ca49e74

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

lib/core-net/private-lib-core-net.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ struct lws_vhost {
534534
#if defined(LWS_WITH_TLS_SESSIONS)
535535
uint32_t tls_session_cache_max;
536536
#endif
537-
537+
uint32_t protocol_init; /* bitmap indicating if protocol initialized */
538538
#if defined(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY) || defined(LWS_WITH_SECURE_STREAMS_CPP)
539539
int8_t ss_refcount;
540540
/**< refcount of number of ss connections with streamtypes using this

lib/core-net/vhost.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ lws_protocol_init_vhost(struct lws_vhost *vh, int *any)
466466
) {
467467
lwsl_vhost_info(vh, "init %s.%s", vh->name,
468468
vh->protocols[n].name);
469+
vh->protocol_init |= 1 << n;
469470
if (vh->protocols[n].callback((struct lws *)lwsa,
470471
LWS_CALLBACK_PROTOCOL_INIT, NULL,
471472
#if !defined(LWS_WITH_PLUGINS)
@@ -1492,7 +1493,7 @@ __lws_vhost_destroy2(struct lws_vhost *vh)
14921493

14931494
lwsl_vhost_debug(vh, "protocol destroy");
14941495

1495-
if (protocol->callback)
1496+
if (protocol->callback && (vh->protocol_init & (1 << n)))
14961497
protocol->callback(&wsi, LWS_CALLBACK_PROTOCOL_DESTROY,
14971498
NULL, NULL, 0);
14981499
protocol++;

0 commit comments

Comments
 (0)