From 7c6cfd2d05fe537901516359bce36985d2137103 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Tue, 12 Mar 2019 09:20:58 +0800 Subject: [PATCH] vhost: fix allocated protocol list freeing at destroy time --- include/libwebsockets/lws-lwsac.h | 2 +- lib/core-net/private.h | 1 + lib/core-net/vhost.c | 8 +++++--- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/libwebsockets/lws-lwsac.h b/include/libwebsockets/lws-lwsac.h index f0584e50b..ea5453cc8 100644 --- a/include/libwebsockets/lws-lwsac.h +++ b/include/libwebsockets/lws-lwsac.h @@ -114,7 +114,7 @@ lwsac_use(struct lwsac **head, size_t ensure, size_t chunk_size); * * Returns NULL if OOM. */ -void * +LWS_VISIBLE LWS_EXTERN void * lwsac_use_zeroed(struct lwsac **head, size_t ensure, size_t chunk_size); /** diff --git a/lib/core-net/private.h b/lib/core-net/private.h index 3716b6bfe..e33fa3cb8 100644 --- a/lib/core-net/private.h +++ b/lib/core-net/private.h @@ -437,6 +437,7 @@ struct lws_vhost { int log_fd; #endif + unsigned int allocated_vhost_protocols:1; unsigned int created_vhost_protocols:1; unsigned int being_destroyed:1; diff --git a/lib/core-net/vhost.c b/lib/core-net/vhost.c index 66733a807..7d485f4f1 100644 --- a/lib/core-net/vhost.c +++ b/lib/core-net/vhost.c @@ -583,9 +583,10 @@ lws_create_vhost(struct lws_context *context, #ifdef LWS_WITH_PLUGINS (context->plugin_list) || #endif - (context->options & LWS_SERVER_OPTION_EXPLICIT_VHOSTS)) + (context->options & LWS_SERVER_OPTION_EXPLICIT_VHOSTS)) { vh->protocols = lwsp; - else { + vh->allocated_vhost_protocols = 1; + } else { vh->protocols = pcols; lws_free(lwsp); } @@ -1047,7 +1048,8 @@ __lws_vhost_destroy2(struct lws_vhost *vh) lws_free(vh->same_vh_protocol_heads); if (context->plugin_list || - (context->options & LWS_SERVER_OPTION_EXPLICIT_VHOSTS)) + (context->options & LWS_SERVER_OPTION_EXPLICIT_VHOSTS) || + vh->allocated_vhost_protocols) lws_free((void *)vh->protocols); #if defined(LWS_WITH_NETWORK) LWS_FOR_EVERY_AVAILABLE_ROLE_START(ar)