server/proxy: Fix double-call to disconnect
authorkubistika <kmizrachi18@gmail.com>
Tue, 28 May 2019 13:09:49 +0000 (16:09 +0300)
committerakallabeth <akallabeth@users.noreply.github.com>
Wed, 26 Jun 2019 12:25:07 +0000 (14:25 +0200)
server/proxy/pf_client.c
server/proxy/pf_server.c

index b2daf90..e3db80a 100644 (file)
@@ -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.
         */
index 261123a..bef3f1b 100644 (file)
@@ -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;