From 1bca1e78206cdf7912815e80b03d78dfb8d57ee2 Mon Sep 17 00:00:00 2001 From: David PHAM-VAN Date: Tue, 28 Jun 2016 14:39:01 -0700 Subject: [PATCH 1/5] Fix Memory Leaks in Disp channel --- channels/disp/client/disp_main.c | 4 ++++ 1 file changed, 4 insertions(+) mode change 100644 => 100755 channels/disp/client/disp_main.c diff --git a/channels/disp/client/disp_main.c b/channels/disp/client/disp_main.c old mode 100644 new mode 100755 index 0f67b7bba..637632c51 --- a/channels/disp/client/disp_main.c +++ b/channels/disp/client/disp_main.c @@ -5,6 +5,7 @@ * Copyright 2013 Marc-Andre Moreau * Copyright 2015 Thincast Technologies GmbH * Copyright 2015 DI (FH) Martin Haimberger + * Copyright 2016 David PHAM-VAN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -317,6 +318,9 @@ static UINT disp_plugin_initialize(IWTSPlugin* pPlugin, IWTSVirtualChannelManage */ static UINT disp_plugin_terminated(IWTSPlugin* pPlugin) { + DISP_PLUGIN* disp = (DISP_PLUGIN*) pPlugin; + free(disp->listener_callback); + free(disp->iface.pInterface); free(pPlugin); return CHANNEL_RC_OK; } From 4265177f9f6cd1d1f38f4f788789e9422ced0883 Mon Sep 17 00:00:00 2001 From: David PHAM-VAN Date: Tue, 28 Jun 2016 14:39:14 -0700 Subject: [PATCH 2/5] Fix Memory Leaks in RdpDR --- channels/rdpdr/client/rdpdr_main.c | 2 ++ 1 file changed, 2 insertions(+) mode change 100644 => 100755 channels/rdpdr/client/rdpdr_main.c diff --git a/channels/rdpdr/client/rdpdr_main.c b/channels/rdpdr/client/rdpdr_main.c old mode 100644 new mode 100755 index 5e5b6198a..2156961da --- a/channels/rdpdr/client/rdpdr_main.c +++ b/channels/rdpdr/client/rdpdr_main.c @@ -7,6 +7,7 @@ * Copyright 2015-2016 Thincast Technologies GmbH * Copyright 2015 DI (FH) Martin Haimberger * Copyright 2016 Armin Novak + * Copyright 2016 David PHAM-VAN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -890,6 +891,7 @@ out: if (error && rdpdr->rdpcontext) setChannelError(rdpdr->rdpcontext, error, "drive_hotplug_thread_func reported an error"); + CloseHandle(rdpdr->stopEvent); ExitThread((DWORD)error); return NULL; } From fe2e4264afa440c1332f186dae088b62e27beea3 Mon Sep 17 00:00:00 2001 From: David PHAM-VAN Date: Tue, 28 Jun 2016 14:39:29 -0700 Subject: [PATCH 3/5] Fix Memory Leaks in RdpSnd --- channels/rdpsnd/client/mac/rdpsnd_mac.c | 2 ++ channels/rdpsnd/client/rdpsnd_main.c | 4 ++++ channels/rdpsnd/client/winmm/rdpsnd_winmm.c | 3 +++ 3 files changed, 9 insertions(+) mode change 100644 => 100755 channels/rdpsnd/client/rdpsnd_main.c diff --git a/channels/rdpsnd/client/mac/rdpsnd_mac.c b/channels/rdpsnd/client/mac/rdpsnd_mac.c index 3c7f13c8d..a73f8ac7f 100644 --- a/channels/rdpsnd/client/mac/rdpsnd_mac.c +++ b/channels/rdpsnd/client/mac/rdpsnd_mac.c @@ -327,6 +327,8 @@ static void rdpsnd_mac_waveplay(rdpsndDevicePlugin* device, RDPSND_WAVE* wave) length = wave->length > audioBuffer->mAudioDataBytesCapacity ? audioBuffer->mAudioDataBytesCapacity : wave->length; CopyMemory(audioBuffer->mAudioData, wave->data, length); + free(wave->data); + wave->data = NULL; audioBuffer->mAudioDataByteSize = length; audioBuffer->mUserData = wave; diff --git a/channels/rdpsnd/client/rdpsnd_main.c b/channels/rdpsnd/client/rdpsnd_main.c old mode 100644 new mode 100755 index 2133339d8..baf0c6401 --- a/channels/rdpsnd/client/rdpsnd_main.c +++ b/channels/rdpsnd/client/rdpsnd_main.c @@ -7,6 +7,7 @@ * Copyright 2012-2013 Marc-Andre Moreau * Copyright 2015 Thincast Technologies GmbH * Copyright 2015 DI (FH) Martin Haimberger + * Copyright 2016 David PHAM-VAN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -1476,6 +1477,9 @@ static VOID VCAPITYPE rdpsnd_virtual_channel_init_event(LPVOID pInitHandle, UINT break; case CHANNEL_EVENT_TERMINATED: + if (plugin->thread != NULL) + if ((error = rdpsnd_virtual_channel_event_disconnected(plugin))) + WLog_ERR(TAG, "rdpsnd_virtual_channel_event_disconnected failed with error %lu!", error); rdpsnd_virtual_channel_event_terminated(plugin); break; } diff --git a/channels/rdpsnd/client/winmm/rdpsnd_winmm.c b/channels/rdpsnd/client/winmm/rdpsnd_winmm.c index 57336ba64..aa9367fee 100644 --- a/channels/rdpsnd/client/winmm/rdpsnd_winmm.c +++ b/channels/rdpsnd/client/winmm/rdpsnd_winmm.c @@ -6,6 +6,7 @@ * Copyright 2010-2012 Vic Lee * Copyright 2015 Thincast Technologies GmbH * Copyright 2015 DI (FH) Martin Haimberger + * Copyright 2016 David PHAM-VAN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -136,6 +137,7 @@ static void CALLBACK rdpsnd_winmm_callback_function(HWAVEOUT hwo, UINT uMsg, DWO winmm->device.WaveConfirm(&(winmm->device), wave); free(lpWaveHdr->lpData); + free(lpWaveHdr); free(wave); } @@ -330,6 +332,7 @@ void rdpsnd_winmm_wave_play(rdpsndDevicePlugin* device, RDPSND_WAVE* wave) { WLog_ERR(TAG, "waveOutWrite failure: %d", mmResult); waveOutUnprepareHeader(winmm->hWaveOut, lpWaveHdr, sizeof(WAVEHDR)); + free(lpWaveHdr); return; } } From f5f3913c1f34dd3252092a167c0946785296c87b Mon Sep 17 00:00:00 2001 From: David PHAM-VAN Date: Wed, 6 Jul 2016 12:12:40 -0700 Subject: [PATCH 4/5] Fix Memory Leaks in Printer Redirection --- channels/printer/client/printer_main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/channels/printer/client/printer_main.c b/channels/printer/client/printer_main.c index 8a8d14285..7b412c28f 100644 --- a/channels/printer/client/printer_main.c +++ b/channels/printer/client/printer_main.c @@ -6,6 +6,7 @@ * Copyright 2015 Thincast Technologies GmbH * Copyright 2015 DI (FH) Martin Haimberger * Copyright 2016 Armin Novak + * Copyright 2016 David PHAM-VAN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -316,6 +317,7 @@ static UINT printer_free(DEVICE* device) printer_dev->printer->Free(printer_dev->printer); free(printer_dev->device.name); + Stream_Free(printer_dev->device.data, TRUE); free(printer_dev); return CHANNEL_RC_OK; From d5dc5b4a3f4a892cca80914be24667d2b5205abe Mon Sep 17 00:00:00 2001 From: David PHAM-VAN Date: Thu, 1 Sep 2016 11:34:38 -0700 Subject: [PATCH 5/5] Fix smartcard channel disconnect --- channels/smartcard/client/smartcard_main.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/channels/smartcard/client/smartcard_main.c b/channels/smartcard/client/smartcard_main.c index e8aa3c556..ec5e5a0f3 100644 --- a/channels/smartcard/client/smartcard_main.c +++ b/channels/smartcard/client/smartcard_main.c @@ -7,6 +7,7 @@ * Copyright 2011 Anthony Tong * Copyright 2015 Thincast Technologies GmbH * Copyright 2015 DI (FH) Martin Haimberger + * Copyright 2016 David PHAM-VAN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -230,6 +231,13 @@ static void smartcard_release_all_contexts(SMARTCARD_DEVICE* smartcard) { if (SCardIsValidContext(hContext) == SCARD_S_SUCCESS) { SCardReleaseContext(hContext); + + if (MessageQueue_PostQuit(pContext->IrpQueue, 0) && (WaitForSingleObject(pContext->thread, INFINITE) == WAIT_FAILED)) + WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", GetLastError()); + + CloseHandle(pContext->thread); + MessageQueue_Free(pContext->IrpQueue); + free(pContext); } } @@ -632,6 +640,11 @@ static void* smartcard_thread_func(void* arg) if ((error = smartcard_complete_irp(smartcard, irp))) { + if (error == CHANNEL_RC_NOT_CONNECTED) + { + error = CHANNEL_RC_OK; + goto out; + } WLog_ERR(TAG, "smartcard_complete_irp failed with error %lu!", error); goto out; }