From 7f1cca78aa9e4cf65cb38c9b741566fbf7dce2d0 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Fri, 6 Nov 2020 13:38:47 +0100 Subject: [PATCH] Clean up drdynvc channels porperly locked. --- channels/drdynvc/client/drdynvc_main.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/channels/drdynvc/client/drdynvc_main.c b/channels/drdynvc/client/drdynvc_main.c index 9dd59a2f5..ddb0703b4 100644 --- a/channels/drdynvc/client/drdynvc_main.c +++ b/channels/drdynvc/client/drdynvc_main.c @@ -1398,15 +1398,23 @@ static DWORD WINAPI drdynvc_virtual_channel_client_thread(LPVOID arg) /* Disconnect remaining dynamic channels that the server did not. * This is required to properly shut down channels by calling the appropriate * event handlers. */ + size_t count = 0; DVCMAN* drdynvcMgr = (DVCMAN*)drdynvc->channel_mgr; - while (ArrayList_Count(drdynvcMgr->channels) > 0) + do { - IWTSVirtualChannel* channel = - (IWTSVirtualChannel*)ArrayList_GetItem(drdynvcMgr->channels, 0); - const UINT32 ChannelId = drdynvc->channel_mgr->GetChannelId(channel); - dvcman_close_channel(drdynvc->channel_mgr, ChannelId, FALSE); - } + ArrayList_Lock(drdynvcMgr->channels); + count = ArrayList_Count(drdynvcMgr->channels); + if (count > 0) + { + IWTSVirtualChannel* channel = + (IWTSVirtualChannel*)ArrayList_GetItem(drdynvcMgr->channels, 0); + const UINT32 ChannelId = drdynvc->channel_mgr->GetChannelId(channel); + dvcman_close_channel(drdynvc->channel_mgr, ChannelId, FALSE); + count--; + } + ArrayList_Unlock(drdynvcMgr->channels); + } while (count > 0); } if (error && drdynvc->rdpcontext)