diff --git a/channels/ainput/server/ainput_main.c b/channels/ainput/server/ainput_main.c index 6bb465025..81a9b5113 100644 --- a/channels/ainput/server/ainput_main.c +++ b/channels/ainput/server/ainput_main.c @@ -292,7 +292,7 @@ static DWORD WINAPI ainput_server_thread_func(LPVOID arg) } } - WTSVirtualChannelClose(ainput->ainput_channel); + (void)WTSVirtualChannelClose(ainput->ainput_channel); ainput->ainput_channel = NULL; if (error && ainput->context.rdpcontext) @@ -369,7 +369,7 @@ static UINT ainput_server_close(ainput_server_context* context) { if (ainput->state != AINPUT_INITIAL) { - WTSVirtualChannelClose(ainput->ainput_channel); + (void)WTSVirtualChannelClose(ainput->ainput_channel); ainput->ainput_channel = NULL; ainput->state = AINPUT_INITIAL; } diff --git a/channels/audin/server/audin.c b/channels/audin/server/audin.c index d67937ab7..ac1e53626 100644 --- a/channels/audin/server/audin.c +++ b/channels/audin/server/audin.c @@ -430,7 +430,7 @@ static DWORD WINAPI audin_server_thread_func(LPVOID arg) out_capacity: Stream_Free(s, TRUE); out: - WTSVirtualChannelClose(audin->audin_channel); + (void)WTSVirtualChannelClose(audin->audin_channel); audin->audin_channel = NULL; if (error && audin->context.rdpcontext) @@ -533,7 +533,7 @@ static BOOL audin_server_close(audin_server_context* context) if (audin->audin_channel) { - WTSVirtualChannelClose(audin->audin_channel); + (void)WTSVirtualChannelClose(audin->audin_channel); audin->audin_channel = NULL; } diff --git a/channels/cliprdr/server/cliprdr_main.c b/channels/cliprdr/server/cliprdr_main.c index 44dc68e07..c8f961d52 100644 --- a/channels/cliprdr/server/cliprdr_main.c +++ b/channels/cliprdr/server/cliprdr_main.c @@ -1355,7 +1355,7 @@ static UINT cliprdr_server_close(CliprdrServerContext* context) if (cliprdr->ChannelHandle) { - WTSVirtualChannelClose(cliprdr->ChannelHandle); + (void)WTSVirtualChannelClose(cliprdr->ChannelHandle); cliprdr->ChannelHandle = NULL; } diff --git a/channels/disp/server/disp_main.c b/channels/disp/server/disp_main.c index 931d8a317..b7bbde684 100644 --- a/channels/disp/server/disp_main.c +++ b/channels/disp/server/disp_main.c @@ -474,7 +474,7 @@ static UINT disp_server_open(DispServerContext* context) return CHANNEL_RC_OK; out_close: - WTSVirtualChannelClose(priv->disp_channel); + (void)WTSVirtualChannelClose(priv->disp_channel); priv->disp_channel = NULL; priv->channelEvent = NULL; return rc; @@ -567,7 +567,7 @@ static UINT disp_server_close(DispServerContext* context) if (priv->disp_channel) { - WTSVirtualChannelClose(priv->disp_channel); + (void)WTSVirtualChannelClose(priv->disp_channel); priv->disp_channel = NULL; } diff --git a/channels/echo/server/echo_main.c b/channels/echo/server/echo_main.c index 9c165261c..c31c55eae 100644 --- a/channels/echo/server/echo_main.c +++ b/channels/echo/server/echo_main.c @@ -219,7 +219,7 @@ static DWORD WINAPI echo_server_thread_func(LPVOID arg) if (!s) { WLog_ERR(TAG, "Stream_New failed!"); - WTSVirtualChannelClose(echo->echo_channel); + (void)WTSVirtualChannelClose(echo->echo_channel); ExitThread(ERROR_NOT_ENOUGH_MEMORY); return ERROR_NOT_ENOUGH_MEMORY; } @@ -239,7 +239,12 @@ static DWORD WINAPI echo_server_thread_func(LPVOID arg) break; Stream_SetPosition(s, 0); - WTSVirtualChannelRead(echo->echo_channel, 0, NULL, 0, &BytesReturned); + if (!WTSVirtualChannelRead(echo->echo_channel, 0, NULL, 0, &BytesReturned)) + { + WLog_ERR(TAG, "WTSVirtualChannelRead failed!"); + error = ERROR_INTERNAL_ERROR; + break; + } if (BytesReturned < 1) continue; @@ -270,7 +275,7 @@ static DWORD WINAPI echo_server_thread_func(LPVOID arg) } Stream_Free(s, TRUE); - WTSVirtualChannelClose(echo->echo_channel); + (void)WTSVirtualChannelClose(echo->echo_channel); echo->echo_channel = NULL; out: diff --git a/channels/encomsp/server/encomsp_main.c b/channels/encomsp/server/encomsp_main.c index f6390dfda..a7bf075b4 100644 --- a/channels/encomsp/server/encomsp_main.c +++ b/channels/encomsp/server/encomsp_main.c @@ -232,7 +232,12 @@ static DWORD WINAPI encomsp_server_thread(LPVOID arg) break; } - WTSVirtualChannelRead(context->priv->ChannelHandle, 0, NULL, 0, &BytesReturned); + if (!WTSVirtualChannelRead(context->priv->ChannelHandle, 0, NULL, 0, &BytesReturned)) + { + WLog_ERR(TAG, "WTSVirtualChannelRead failed!"); + error = ERROR_INTERNAL_ERROR; + break; + } if (BytesReturned < 1) continue; @@ -364,7 +369,7 @@ void encomsp_server_context_free(EncomspServerContext* context) if (context) { if (context->priv->ChannelHandle != INVALID_HANDLE_VALUE) - WTSVirtualChannelClose(context->priv->ChannelHandle); + (void)WTSVirtualChannelClose(context->priv->ChannelHandle); free(context->priv); free(context); diff --git a/channels/location/server/location_main.c b/channels/location/server/location_main.c index bea88edee..549cfc019 100644 --- a/channels/location/server/location_main.c +++ b/channels/location/server/location_main.c @@ -426,7 +426,7 @@ static DWORD WINAPI location_server_thread_func(LPVOID arg) } } - WTSVirtualChannelClose(location->location_channel); + (void)WTSVirtualChannelClose(location->location_channel); location->location_channel = NULL; if (error && location->context.rdpcontext) @@ -493,7 +493,7 @@ static UINT location_server_close(LocationServerContext* context) { if (location->state != LOCATION_INITIAL) { - WTSVirtualChannelClose(location->location_channel); + (void)WTSVirtualChannelClose(location->location_channel); location->location_channel = NULL; location->state = LOCATION_INITIAL; } diff --git a/channels/rail/server/rail_main.c b/channels/rail/server/rail_main.c index 8161d1751..bc569bba7 100644 --- a/channels/rail/server/rail_main.c +++ b/channels/rail/server/rail_main.c @@ -1462,7 +1462,7 @@ out_stop_event: CloseHandle(context->priv->stopEvent); context->priv->stopEvent = NULL; out_close: - WTSVirtualChannelClose(context->priv->rail_channel); + (void)WTSVirtualChannelClose(context->priv->rail_channel); context->priv->rail_channel = NULL; return error; } @@ -1489,7 +1489,7 @@ static BOOL rail_server_stop(RailServerContext* context) if (priv->rail_channel) { - WTSVirtualChannelClose(priv->rail_channel); + (void)WTSVirtualChannelClose(priv->rail_channel); priv->rail_channel = NULL; } diff --git a/channels/rdpdr/server/rdpdr_main.c b/channels/rdpdr/server/rdpdr_main.c index 57c1da52d..70c13fb1c 100644 --- a/channels/rdpdr/server/rdpdr_main.c +++ b/channels/rdpdr/server/rdpdr_main.c @@ -2186,7 +2186,7 @@ static UINT rdpdr_server_stop(RdpdrServerContext* context) if (context->priv->ChannelHandle) { - WTSVirtualChannelClose(context->priv->ChannelHandle); + (void)WTSVirtualChannelClose(context->priv->ChannelHandle); context->priv->ChannelHandle = NULL; } return CHANNEL_RC_OK; diff --git a/channels/rdpecam/server/camera_device_enumerator_main.c b/channels/rdpecam/server/camera_device_enumerator_main.c index 27523b0f1..195ec8454 100644 --- a/channels/rdpecam/server/camera_device_enumerator_main.c +++ b/channels/rdpecam/server/camera_device_enumerator_main.c @@ -418,7 +418,7 @@ static DWORD WINAPI enumerator_server_thread_func(LPVOID arg) } } - WTSVirtualChannelClose(enumerator->enumerator_channel); + (void)WTSVirtualChannelClose(enumerator->enumerator_channel); enumerator->enumerator_channel = NULL; if (error && enumerator->context.rdpcontext) @@ -486,7 +486,7 @@ static UINT enumerator_server_close(CamDevEnumServerContext* context) { if (enumerator->state != ENUMERATOR_INITIAL) { - WTSVirtualChannelClose(enumerator->enumerator_channel); + (void)WTSVirtualChannelClose(enumerator->enumerator_channel); enumerator->enumerator_channel = NULL; enumerator->state = ENUMERATOR_INITIAL; } diff --git a/channels/rdpecam/server/camera_device_main.c b/channels/rdpecam/server/camera_device_main.c index ce0774c51..0d3acdd2e 100644 --- a/channels/rdpecam/server/camera_device_main.c +++ b/channels/rdpecam/server/camera_device_main.c @@ -571,7 +571,7 @@ static DWORD WINAPI device_server_thread_func(LPVOID arg) } } - WTSVirtualChannelClose(device->device_channel); + (void)WTSVirtualChannelClose(device->device_channel); device->device_channel = NULL; if (error && device->context.rdpcontext) @@ -638,7 +638,7 @@ static UINT device_server_close(CameraDeviceServerContext* context) { if (device->state != CAMERA_DEVICE_INITIAL) { - WTSVirtualChannelClose(device->device_channel); + (void)WTSVirtualChannelClose(device->device_channel); device->device_channel = NULL; device->state = CAMERA_DEVICE_INITIAL; } diff --git a/channels/rdpei/server/rdpei_main.c b/channels/rdpei/server/rdpei_main.c index c87a045db..c4d713a5e 100644 --- a/channels/rdpei/server/rdpei_main.c +++ b/channels/rdpei/server/rdpei_main.c @@ -136,7 +136,7 @@ UINT rdpei_server_init(RdpeiServerContext* context) return CHANNEL_RC_OK; out_close: - WTSVirtualChannelClose(priv->channelHandle); + (void)WTSVirtualChannelClose(priv->channelHandle); return CHANNEL_RC_INITIALIZATION_ERROR; } @@ -161,7 +161,7 @@ void rdpei_server_context_free(RdpeiServerContext* context) if (priv) { if (priv->channelHandle != INVALID_HANDLE_VALUE) - WTSVirtualChannelClose(priv->channelHandle); + (void)WTSVirtualChannelClose(priv->channelHandle); Stream_Free(priv->inputStream, TRUE); } free(priv); diff --git a/channels/rdpemsc/server/mouse_cursor_main.c b/channels/rdpemsc/server/mouse_cursor_main.c index d7d2f789b..1e5225dfb 100644 --- a/channels/rdpemsc/server/mouse_cursor_main.c +++ b/channels/rdpemsc/server/mouse_cursor_main.c @@ -375,7 +375,7 @@ static DWORD WINAPI mouse_cursor_server_thread_func(LPVOID arg) } } - WTSVirtualChannelClose(mouse_cursor->mouse_cursor_channel); + (void)WTSVirtualChannelClose(mouse_cursor->mouse_cursor_channel); mouse_cursor->mouse_cursor_channel = NULL; if (error && mouse_cursor->context.rdpcontext) @@ -443,7 +443,7 @@ static UINT mouse_cursor_server_close(MouseCursorServerContext* context) { if (mouse_cursor->state != MOUSE_CURSOR_INITIAL) { - WTSVirtualChannelClose(mouse_cursor->mouse_cursor_channel); + (void)WTSVirtualChannelClose(mouse_cursor->mouse_cursor_channel); mouse_cursor->mouse_cursor_channel = NULL; mouse_cursor->state = MOUSE_CURSOR_INITIAL; } diff --git a/channels/rdpgfx/server/rdpgfx_main.c b/channels/rdpgfx/server/rdpgfx_main.c index 534c5577c..3b21d03cb 100644 --- a/channels/rdpgfx/server/rdpgfx_main.c +++ b/channels/rdpgfx/server/rdpgfx_main.c @@ -1649,7 +1649,7 @@ BOOL rdpgfx_server_close(RdpgfxServerContext* context) if (priv->rdpgfx_channel) { - WTSVirtualChannelClose(priv->rdpgfx_channel); + (void)WTSVirtualChannelClose(priv->rdpgfx_channel); priv->rdpgfx_channel = NULL; } diff --git a/channels/rdpsnd/server/rdpsnd_main.c b/channels/rdpsnd/server/rdpsnd_main.c index f1b8fcfbb..9d3e3e616 100644 --- a/channels/rdpsnd/server/rdpsnd_main.c +++ b/channels/rdpsnd/server/rdpsnd_main.c @@ -965,7 +965,7 @@ out_pdu: Stream_Free(context->priv->rdpsnd_pdu, TRUE); context->priv->rdpsnd_pdu = NULL; out_close: - WTSVirtualChannelClose(context->priv->ChannelHandle); + (void)WTSVirtualChannelClose(context->priv->ChannelHandle); context->priv->ChannelHandle = NULL; return error; } @@ -1015,7 +1015,7 @@ static UINT rdpsnd_server_stop(RdpsndServerContext* context) if (context->priv->ChannelHandle) { - WTSVirtualChannelClose(context->priv->ChannelHandle); + (void)WTSVirtualChannelClose(context->priv->ChannelHandle); context->priv->ChannelHandle = NULL; } diff --git a/channels/remdesk/server/remdesk_main.c b/channels/remdesk/server/remdesk_main.c index 5aed1e3dd..90f7e97ec 100644 --- a/channels/remdesk/server/remdesk_main.c +++ b/channels/remdesk/server/remdesk_main.c @@ -728,7 +728,7 @@ void remdesk_server_context_free(RemdeskServerContext* context) if (context) { if (context->priv->ChannelHandle != INVALID_HANDLE_VALUE) - WTSVirtualChannelClose(context->priv->ChannelHandle); + (void)WTSVirtualChannelClose(context->priv->ChannelHandle); free(context->priv); free(context); diff --git a/channels/telemetry/server/telemetry_main.c b/channels/telemetry/server/telemetry_main.c index 0d8e0476c..329fd7b55 100644 --- a/channels/telemetry/server/telemetry_main.c +++ b/channels/telemetry/server/telemetry_main.c @@ -295,7 +295,7 @@ static DWORD WINAPI telemetry_server_thread_func(LPVOID arg) } } - WTSVirtualChannelClose(telemetry->telemetry_channel); + (void)WTSVirtualChannelClose(telemetry->telemetry_channel); telemetry->telemetry_channel = NULL; if (error && telemetry->context.rdpcontext) @@ -362,7 +362,7 @@ static UINT telemetry_server_close(TelemetryServerContext* context) { if (telemetry->state != TELEMETRY_INITIAL) { - WTSVirtualChannelClose(telemetry->telemetry_channel); + (void)WTSVirtualChannelClose(telemetry->telemetry_channel); telemetry->telemetry_channel = NULL; telemetry->state = TELEMETRY_INITIAL; } diff --git a/libfreerdp/core/server.c b/libfreerdp/core/server.c index fe3c2cc5a..72cffdd72 100644 --- a/libfreerdp/core/server.c +++ b/libfreerdp/core/server.c @@ -1066,7 +1066,7 @@ VOID WINAPI FreeRDP_WTSCloseServer(HANDLE hServer) if (vcm->drdynvc_channel) { - WTSVirtualChannelClose(vcm->drdynvc_channel); + (void)WTSVirtualChannelClose(vcm->drdynvc_channel); vcm->drdynvc_channel = NULL; } diff --git a/server/Sample/sfreerdp.c b/server/Sample/sfreerdp.c index edf4cea0a..c873efcc5 100644 --- a/server/Sample/sfreerdp.c +++ b/server/Sample/sfreerdp.c @@ -93,7 +93,7 @@ static void test_peer_context_free(freerdp_peer* client, rdpContext* ctx) nsc_context_free(context->nsc_context); if (context->debug_channel) - WTSVirtualChannelClose(context->debug_channel); + (void)WTSVirtualChannelClose(context->debug_channel); sf_peer_audin_uninit(context); @@ -610,7 +610,6 @@ fail: static DWORD WINAPI tf_debug_channel_thread_func(LPVOID arg) { void* fd = NULL; - wStream* s = NULL; void* buffer = NULL; DWORD BytesReturned = 0; ULONG written = 0; @@ -627,8 +626,12 @@ static DWORD WINAPI tf_debug_channel_thread_func(LPVOID arg) return 0; } - s = Stream_New(NULL, 4096); - WTSVirtualChannelWrite(context->debug_channel, (PCHAR) "test1", 5, &written); + wStream* s = Stream_New(NULL, 4096); + if (!s) + goto fail; + + if (!WTSVirtualChannelWrite(context->debug_channel, (PCHAR) "test1", 5, &written)) + goto fail; while (1) { @@ -892,7 +895,8 @@ static BOOL tf_peer_keyboard_event(rdpInput* input, UINT16 flags, UINT8 code) if (tcontext->debug_channel) { ULONG written = 0; - WTSVirtualChannelWrite(tcontext->debug_channel, (PCHAR) "test2", 5, &written); + if (!WTSVirtualChannelWrite(tcontext->debug_channel, (PCHAR) "test2", 5, &written)) + return FALSE; } } else if (((flags & KBD_FLAGS_RELEASE) == 0) && code == RDP_SCANCODE_KEY_X) /* 'x' key */ diff --git a/winpr/include/winpr/wtsapi.h b/winpr/include/winpr/wtsapi.h index 9a0ee6ae6..6bb64fc6c 100644 --- a/winpr/include/winpr/wtsapi.h +++ b/winpr/include/winpr/wtsapi.h @@ -1074,14 +1074,16 @@ extern "C" WINPR_API BOOL WINAPI WTSWaitSystemEvent(HANDLE hServer, DWORD EventMask, DWORD* pEventFlags); + WINPR_API BOOL WINAPI WTSVirtualChannelClose(HANDLE hChannelHandle); + + WINPR_ATTR_MALLOC(WTSVirtualChannelClose, 1) WINPR_API HANDLE WINAPI WTSVirtualChannelOpen(HANDLE hServer, DWORD SessionId, LPSTR pVirtualName); + WINPR_ATTR_MALLOC(WTSVirtualChannelClose, 1) WINPR_API HANDLE WINAPI WTSVirtualChannelOpenEx(DWORD SessionId, LPSTR pVirtualName, DWORD flags); - WINPR_API BOOL WINAPI WTSVirtualChannelClose(HANDLE hChannelHandle); - WINPR_API BOOL WINAPI WTSVirtualChannelRead(HANDLE hChannelHandle, ULONG TimeOut, PCHAR Buffer, ULONG BufferSize, PULONG pBytesRead);