[core] add null checks

when a client instance disconnects it might have failed to allocate some
resources. So ensure all used ones are there
This commit is contained in:
Armin Novak
2026-02-27 19:03:34 +01:00
parent 7c405bf644
commit 9a9c74b69e
3 changed files with 21 additions and 9 deletions

View File

@@ -302,14 +302,13 @@ BOOL rdp_client_connect(rdpRdp* rdp)
{
UINT32 SelectedProtocol = 0;
BOOL status = 0;
rdpSettings* settings = nullptr;
/* make sure SSL is initialize for earlier enough for crypto, by taking advantage of winpr SSL
* FIPS flag for openssl initialization */
DWORD flags = WINPR_SSL_INIT_DEFAULT;
WINPR_ASSERT(rdp);
settings = rdp->settings;
rdpSettings* settings = rdp->settings;
WINPR_ASSERT(settings);
if (!rdp_client_reset_codecs(rdp->context))
@@ -318,7 +317,9 @@ BOOL rdp_client_connect(rdpRdp* rdp)
if (settings->FIPSMode)
flags |= WINPR_SSL_INIT_ENABLE_FIPS;
winpr_InitializeSSL(flags);
if (!winpr_InitializeSSL(flags))
return FALSE;
rdp_log_build_warnings(rdp);
/* FIPS Mode forces the following and overrides the following(by happening later */
@@ -353,6 +354,9 @@ BOOL rdp_client_connect(rdpRdp* rdp)
const UINT32 port = settings->ServerPort;
WINPR_ASSERT(port <= UINT32_MAX);
if (!rdp->nego)
return FALSE;
nego_init(rdp->nego);
nego_set_target(rdp->nego, hostname, (UINT16)port);
@@ -502,8 +506,11 @@ BOOL rdp_client_disconnect(rdpRdp* rdp)
if (!rdp_client_transition_to_state(rdp, CONNECTION_STATE_INITIAL))
return FALSE;
if (freerdp_channels_disconnect(context->channels, context->instance) != CHANNEL_RC_OK)
return FALSE;
if (context->channels)
{
if (freerdp_channels_disconnect(context->channels, context->instance) != CHANNEL_RC_OK)
return FALSE;
}
freerdp_client_codecs_free(context->codecs);
context->codecs = nullptr;

View File

@@ -643,7 +643,8 @@ BOOL freerdp_disconnect(freerdp* instance)
}
}
freerdp_channels_close(instance->context->channels, instance);
if (instance->context->channels)
freerdp_channels_close(instance->context->channels, instance);
IFCALL(instance->PostFinalDisconnect, instance);

View File

@@ -497,9 +497,13 @@ BOOL utils_reload_channels(rdpContext* context)
{
WINPR_ASSERT(context);
freerdp_channels_disconnect(context->channels, context->instance);
freerdp_channels_close(context->channels, context->instance);
freerdp_channels_free(context->channels);
if (context->channels)
{
freerdp_channels_disconnect(context->channels, context->instance);
freerdp_channels_close(context->channels, context->instance);
freerdp_channels_free(context->channels);
}
context->channels = freerdp_channels_new(context->instance);
WINPR_ASSERT(context->channels);
freerdp_channels_register_instance(context->channels, context->instance);