[winpr,wtsapi] improve API usage

* Mark WTSVirtualChannelOpen and WTSVirtualChannelOpenEx with
  WINPR_ATTR_MALLOC to enforce compiler checks for resource cleanup
* Fix unused result warnings, use the result or cast to (void) where not
  requierd
This commit is contained in:
akallabeth 2024-09-14 21:07:03 +02:00
parent a1cef8dd85
commit 8b6091a007
No known key found for this signature in database
GPG Key ID: A49454A3FC909FD5
20 changed files with 55 additions and 39 deletions

View File

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

View File

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

View File

@ -1355,7 +1355,7 @@ static UINT cliprdr_server_close(CliprdrServerContext* context)
if (cliprdr->ChannelHandle)
{
WTSVirtualChannelClose(cliprdr->ChannelHandle);
(void)WTSVirtualChannelClose(cliprdr->ChannelHandle);
cliprdr->ChannelHandle = NULL;
}

View File

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

View File

@ -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:

View File

@ -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);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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);

View File

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

View File

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

View File

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

View File

@ -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);

View File

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

View File

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

View File

@ -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 */

View File

@ -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);