diff --git a/channels/rdpdr/disk/disk_main.c b/channels/rdpdr/disk/disk_main.c index 1bf546e08..d0496b1d3 100644 --- a/channels/rdpdr/disk/disk_main.c +++ b/channels/rdpdr/disk/disk_main.c @@ -555,6 +555,7 @@ static void disk_free(DEVICE* device) DISK_FILE* file; freerdp_thread_stop(disk->thread); + freerdp_thread_free(disk->thread); while ((irp = (IRP*)list_dequeue(disk->irp_list)) != NULL) irp->Discard(irp); diff --git a/channels/rdpdr/printer/printer_main.c b/channels/rdpdr/printer/printer_main.c index ef961e6bf..59cfbc548 100644 --- a/channels/rdpdr/printer/printer_main.c +++ b/channels/rdpdr/printer/printer_main.c @@ -210,6 +210,7 @@ static void printer_free(DEVICE* device) IRP* irp; freerdp_thread_stop(printer_dev->thread); + freerdp_thread_free(printer_dev->thread); while ((irp = (IRP*)list_dequeue(printer_dev->irp_list)) != NULL) irp->Discard(irp); diff --git a/include/freerdp/utils/thread.h b/include/freerdp/utils/thread.h index 4739c03a6..10fe682a6 100644 --- a/include/freerdp/utils/thread.h +++ b/include/freerdp/utils/thread.h @@ -43,11 +43,15 @@ struct _freerdp_thread FREERDP_API freerdp_thread* freerdp_thread_new(void); FREERDP_API void freerdp_thread_start(freerdp_thread* thread, void* func, void* arg); FREERDP_API void freerdp_thread_stop(freerdp_thread* thread); +FREERDP_API void freerdp_thread_free(freerdp_thread* thread); #define freerdp_thread_wait(_t) wait_obj_select(_t->signals, _t->num_signals, -1) #define freerdp_thread_wait_timeout(_t, _timeout) wait_obj_select(_t->signals, _t->num_signals, _timeout) #define freerdp_thread_is_stopped(_t) wait_obj_is_set(_t->signals[0]) -#define freerdp_thread_quit(_t) _t->status = -1 +#define freerdp_thread_is_running(_t) (_t->status == 1) +#define freerdp_thread_quit(_t) do { \ + _t->status = -1; \ + wait_obj_clear(_t->signals[0]); } while (0) #define freerdp_thread_signal(_t) wait_obj_set(_t->signals[1]) #define freerdp_thread_reset(_t) wait_obj_clear(_t->signals[1]) #define freerdp_thread_lock(_t) freerdp_mutex_lock(_t->mutex) diff --git a/libfreerdp-utils/svc_plugin.c b/libfreerdp-utils/svc_plugin.c index 3baf3881e..72379d57d 100644 --- a/libfreerdp-utils/svc_plugin.c +++ b/libfreerdp-utils/svc_plugin.c @@ -303,6 +303,7 @@ static void svc_plugin_process_terminated(rdpSvcPlugin* plugin) svc_data_in_item* item; freerdp_thread_stop(plugin->priv->thread); + freerdp_thread_free(plugin->priv->thread); plugin->channel_entry_points.pVirtualChannelClose(plugin->priv->open_handle); xfree(plugin->channel_entry_points.pExtendedData); diff --git a/libfreerdp-utils/thread.c b/libfreerdp-utils/thread.c index 3f95df1a8..49e7ff494 100644 --- a/libfreerdp-utils/thread.c +++ b/libfreerdp-utils/thread.c @@ -72,6 +72,11 @@ void freerdp_thread_stop(freerdp_thread* thread) i++; freerdp_usleep(100); } +} + +void freerdp_thread_free(freerdp_thread* thread) +{ + int i; for (i = 0; i < thread->num_signals; i++) wait_obj_free(thread->signals[i]);