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 };