From f795fc2670c047d22d2f67278eeb0cdab0f020f3 Mon Sep 17 00:00:00 2001 From: kubistika Date: Thu, 30 May 2019 11:22:50 +0300 Subject: [PATCH] server/proxy: Fix race-condition The client's `ClientStop` callback wasn't set, therefore calling freerdp_client_stop wasn't really blocking until it has stopped, and a race condition occured. Fixed by registring to `ClientStop` callback and waiting for the client thread to finish. --- server/proxy/pf_client.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/server/proxy/pf_client.c b/server/proxy/pf_client.c index e3db80ae1..348843cb2 100644 --- a/server/proxy/pf_client.c +++ b/server/proxy/pf_client.c @@ -356,6 +356,22 @@ static BOOL pf_client_client_new(freerdp* instance, rdpContext* context) return TRUE; } +static int pf_client_client_stop(rdpContext* context) +{ + pClientContext* pc = (pClientContext*) context; + pServerContext* ps = pc->pdata->ps; + freerdp_abort_connect(context->instance); + + if (ps->thread) + { + WaitForSingleObject(ps->thread, INFINITE); + CloseHandle(ps->thread); + ps->thread = NULL; + } + + return 0; +} + int RdpClientEntry(RDP_CLIENT_ENTRY_POINTS* pEntryPoints) { ZeroMemory(pEntryPoints, sizeof(RDP_CLIENT_ENTRY_POINTS)); @@ -365,6 +381,7 @@ int RdpClientEntry(RDP_CLIENT_ENTRY_POINTS* pEntryPoints) pEntryPoints->ContextSize = sizeof(pClientContext); /* Client init and finish */ pEntryPoints->ClientNew = pf_client_client_new; + pEntryPoints->ClientStop = pf_client_client_stop; return 0; }