From 39f6379c0cf1e193f093c9e2032d640a2ec272a3 Mon Sep 17 00:00:00 2001 From: Dmitry Potapov Date: Wed, 16 Mar 2022 15:24:22 +0300 Subject: [PATCH] vhost: remove from defer binding on destroy If a vhost is removed, it should remove references to it from the defer binding list to avoid dangling pointers, which can crash the application. --- lib/core-net/vhost.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/core-net/vhost.c b/lib/core-net/vhost.c index 298bf01e8..74d61417e 100644 --- a/lib/core-net/vhost.c +++ b/lib/core-net/vhost.c @@ -1437,6 +1437,20 @@ __lws_vhost_destroy2(struct lws_vhost *vh) // lwsl_info("%s: %s\n", __func__, vh->name); + /* + * remove ourselves from the defer binding list + */ + lws_start_foreach_llp(struct lws_vhost **, pv, + vh->context->no_listener_vhost_list) { + if (*pv == vh) { + lwsl_debug("deferred iface: removing vh %s\n", + (*pv)->name); + *pv = vh->no_listener_vhost_list; + vh->no_listener_vhost_list = NULL; + break; + } + } lws_end_foreach_llp(pv, no_listener_vhost_list); + /* * let the protocols destroy the per-vhost protocol objects */