From c5012fac1def0f2be90136f642a3a8814a21274b Mon Sep 17 00:00:00 2001 From: Andy Green Date: Mon, 23 Jul 2018 21:17:33 +0800 Subject: [PATCH] client: handle oom4 fail path for vhost dll_active_client_conns list Client connections can put themselves on the active client list before they have survived the client connect process past oom4, which can fail out without close processing. So ensure the wsi destruction on oom4 removes it from the list. --- lib/roles/http/client/client-handshake.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/roles/http/client/client-handshake.c b/lib/roles/http/client/client-handshake.c index bc9513787..bda434ff6 100644 --- a/lib/roles/http/client/client-handshake.c +++ b/lib/roles/http/client/client-handshake.c @@ -177,6 +177,7 @@ create_new_conn: lws_dll_is_null(&wsi->dll_client_transaction_queue) && lws_dll_is_null(&wsi->dll_active_client_conns)) { lws_vhost_lock(wsi->vhost); + /* caution... we will have to unpick this on oom4 path */ lws_dll_lws_add_front(&wsi->dll_active_client_conns, &wsi->vhost->dll_active_client_conns); lws_vhost_unlock(wsi->vhost); @@ -581,6 +582,16 @@ oom4: if (wsi->position_in_fds_table != LWS_NO_FDS_POS) goto failed1; lws_remove_from_timeout_list(wsi); + /* + * We can't be an active client connection any more, if we thought + * that was what we were going to be doing. It should be if we are + * failing by oom4 path, we are still called by + * lws_client_connect_via_info() and will be returning NULL to that, + * so nobody else should have had a chance to queue on us. + */ + lws_vhost_lock(wsi->vhost); + lws_dll_lws_remove(&wsi->dll_active_client_conns); + lws_vhost_unlock(wsi->vhost); #if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) lws_header_table_detach(wsi, 0); #endif