From: kubistika Date: Tue, 28 May 2019 13:09:49 +0000 (+0300) Subject: server/proxy: Fix double-call to disconnect X-Git-Tag: 2.0.0~446 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c0cece1064cdaa484d46b64b6479cd941d6d9cb2;p=platform%2Fupstream%2Ffreerdp.git server/proxy: Fix double-call to disconnect --- diff --git a/server/proxy/pf_client.c b/server/proxy/pf_client.c index b2daf90..e3db80a 100644 --- a/server/proxy/pf_client.c +++ b/server/proxy/pf_client.c @@ -183,8 +183,6 @@ static void pf_client_post_disconnect(freerdp* instance) { pClientContext* context; proxyData* pdata; - rdpContext* ps; - freerdp_peer* peer; if (!instance) return; @@ -194,8 +192,6 @@ static void pf_client_post_disconnect(freerdp* instance) context = (pClientContext*) instance->context; pdata = context->pdata; - ps = (rdpContext*) pdata->ps; - peer = ps->peer; PubSub_UnsubscribeChannelConnected(instance->context->pubSub, pf_OnChannelConnectedEventHandler); @@ -204,13 +200,7 @@ static void pf_client_post_disconnect(freerdp* instance) PubSub_UnsubscribeErrorInfo(instance->context->pubSub, pf_OnErrorInfo); gdi_free(instance); - if (!pf_common_connection_aborted_by_peer(pdata)) - { - SetEvent(pdata->connectionClosed); - WLog_INFO(TAG, "connectionClosed event is not set; closing connection with client"); - peer->Disconnect(peer); - } - + SetEvent(pdata->connectionClosed); /* It's important to avoid calling `freerdp_peer_context_free` and `freerdp_peer_free` here, * in order to avoid double-free. Those objects will be freed by the server when needed. */ diff --git a/server/proxy/pf_server.c b/server/proxy/pf_server.c index 261123a..bef3f1b 100644 --- a/server/proxy/pf_server.c +++ b/server/proxy/pf_server.c @@ -61,7 +61,7 @@ static void pf_server_handle_client_disconnection(freerdp_peer* client) ps = (pServerContext*)client->context; pc = (rdpContext*) ps->pdata->pc; pdata = ps->pdata; - WLog_INFO(TAG, "Client %s disconnected; closing connection with server %s", + WLog_INFO(TAG, "Client %s disconnected; closing proxy's client <> target server connection %s", client->hostname, pc->settings->ServerHostname); /* Mark connection closed for sContext */ SetEvent(pdata->connectionClosed); @@ -298,19 +298,22 @@ static DWORD WINAPI pf_server_handle_client(LPVOID arg) eventCount += tmp; } eventHandles[eventCount++] = ChannelEvent; + eventHandles[eventCount++] = pdata->connectionClosed; eventHandles[eventCount++] = WTSVirtualChannelManagerGetEventHandle(ps->vcm); status = WaitForMultipleObjects(eventCount, eventHandles, FALSE, INFINITE); if (status == WAIT_FAILED) { - /* Ignore wait fails that are caused by legitimate client disconnections */ - if (pf_common_connection_aborted_by_peer(pdata)) - break; - WLog_ERR(TAG, "WaitForMultipleObjects failed (errno: %d)", errno); break; } + if (pf_common_connection_aborted_by_peer(pdata)) + { + WLog_INFO(TAG, "proxy's client disconnected, closing connection with client %s", client->hostname); + break; + } + if (client->CheckFileDescriptor(client) != TRUE) break;