diff --git a/channels/rdpdr/client/rdpdr_main.c b/channels/rdpdr/client/rdpdr_main.c index e48999887..27dd9e570 100644 --- a/channels/rdpdr/client/rdpdr_main.c +++ b/channels/rdpdr/client/rdpdr_main.c @@ -434,15 +434,16 @@ static void* drive_hotplug_thread_func(void* arg) struct timeval tv; int rv; - rdpdr = (rdpdrPlugin *)arg; + rdpdr = (rdpdrPlugin*) arg; - rdpdr->stop_event = CreateEvent(NULL, TRUE, FALSE, NULL); + rdpdr->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL); mfd = open("/proc/mounts", O_RDONLY, 0); + if (mfd < 0) { - fprintf(stderr, "ERROR: Unable to open /proc/mounts."); - return NULL; + fprintf(stderr, "ERROR: Unable to open /proc/mounts."); + return NULL; } FD_ZERO(&rfds); @@ -452,7 +453,7 @@ static void* drive_hotplug_thread_func(void* arg) while ((rv = select(mfd+1, NULL, NULL, &rfds, &tv)) >= 0) { - if (WaitForSingleObject(rdpdr->stop_event, 0) == WAIT_OBJECT_0) + if (WaitForSingleObject(rdpdr->stopEvent, 0) == WAIT_OBJECT_0) break; if (FD_ISSET(mfd, &rfds)) @@ -467,13 +468,19 @@ static void* drive_hotplug_thread_func(void* arg) tv.tv_usec = 0; } - return NULL; + return NULL; } static void drive_hotplug_thread_terminate(rdpdrPlugin* rdpdr) { - if (rdpdr->stop_event) - SetEvent(rdpdr->stop_event); + if (rdpdr->hotplugThread) + { + if (rdpdr->stopEvent) + SetEvent(rdpdr->stopEvent); + + WaitForSingleObject(rdpdr->hotplugThread, INFINITE); + rdpdr->hotplugThread = NULL; + } } #endif @@ -493,11 +500,14 @@ static void rdpdr_process_connect(rdpdrPlugin* rdpdr) for (index = 0; index < settings->DeviceCount; index++) { device = settings->DeviceArray[index]; - if (strcmp(device->Name, "*") == 0) + + if (device->Name && (strcmp(device->Name, "*") == 0)) { - rdpdr->hotplug_thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)drive_hotplug_thread_func, rdpdr, 0, NULL); + rdpdr->hotplugThread = CreateThread(NULL, 0, + (LPTHREAD_START_ROUTINE) drive_hotplug_thread_func, rdpdr, 0, NULL); continue; } + devman_load_device_service(rdpdr->devman, device); } } @@ -939,8 +949,6 @@ static void rdpdr_virtual_channel_event_terminated(rdpdrPlugin* rdpdr) drive_hotplug_thread_terminate(rdpdr); - WaitForSingleObject(rdpdr->hotplug_thread, INFINITE); - rdpdr->channelEntryPoints.pVirtualChannelClose(rdpdr->OpenHandle); if (rdpdr->data_in) diff --git a/channels/rdpdr/client/rdpdr_main.h b/channels/rdpdr/client/rdpdr_main.h index a0d6dd8f6..94da4227e 100644 --- a/channels/rdpdr/client/rdpdr_main.h +++ b/channels/rdpdr/client/rdpdr_main.h @@ -54,11 +54,11 @@ struct rdpdr_plugin char computerName[256]; /* hotplug support */ - HANDLE hotplug_thread; + HANDLE hotplugThread; #ifdef _WIN32 HWND hotplug_wnd; #else - HANDLE stop_event; + HANDLE stopEvent; #endif }; diff --git a/libfreerdp/core/bulk.c b/libfreerdp/core/bulk.c index 1b1273800..4956b007c 100644 --- a/libfreerdp/core/bulk.c +++ b/libfreerdp/core/bulk.c @@ -77,7 +77,7 @@ int bulk_decompress(rdpBulk* bulk, BYTE* pSrcData, UINT32 SrcSize, BYTE** ppDstD { *ppDstData = pSrcData; *pDstSize = SrcSize; - status = 1; + status = 0; } if (status >= 0) diff --git a/libfreerdp/core/fastpath.c b/libfreerdp/core/fastpath.c index ba9af739a..9d5157567 100644 --- a/libfreerdp/core/fastpath.c +++ b/libfreerdp/core/fastpath.c @@ -337,6 +337,7 @@ static int fastpath_recv_update_data(rdpFastPath* fastpath, wStream* s) rdpRdp* rdp; int next_pos; wStream* cs; + int bulkStatus; UINT32 totalSize; BYTE updateCode; BYTE fragmentation; @@ -365,8 +366,18 @@ static int fastpath_recv_update_data(rdpFastPath* fastpath, wStream* s) cs = s; next_pos = Stream_GetPosition(s) + size; - if (bulk_decompress(rdp->bulk, Stream_Pointer(s), size, &pDstData, &DstSize, compressionFlags)) + bulkStatus = bulk_decompress(rdp->bulk, Stream_Pointer(s), size, &pDstData, &DstSize, compressionFlags); + + if (bulkStatus < 0) { + fprintf(stderr, "bulk_decompress() failed\n"); + return -1; + } + + if (bulkStatus > 0) + { + /* data was compressed, copy from decompression buffer */ + size = DstSize; cs = StreamPool_Take(transport->ReceivePool, DstSize); @@ -375,11 +386,6 @@ static int fastpath_recv_update_data(rdpFastPath* fastpath, wStream* s) Stream_SealLength(cs); Stream_SetPosition(cs, 0); } - else - { - fprintf(stderr, "bulk_decompress() failed\n"); - Stream_Seek(s, size); - } if (fragmentation == FASTPATH_FRAGMENT_SINGLE) {