Refactored rdpRdp cleanup handling

This commit is contained in:
akallabeth 2021-09-17 09:25:30 +02:00 committed by akallabeth
parent 6b24c2be10
commit d1b58ab263

View File

@ -1894,89 +1894,100 @@ fail:
return NULL;
}
BOOL rdp_reset(rdpRdp* rdp)
static void rdp_reset_free(rdpRdp* rdp)
{
rdpContext* context;
rdpSettings* settings;
context = rdp->context;
settings = rdp->settings;
bulk_reset(rdp->bulk);
WINPR_ASSERT(rdp);
winpr_RC4_Free(rdp->rc4_decrypt_key);
winpr_RC4_Free(rdp->rc4_encrypt_key);
winpr_Cipher_Free(rdp->fips_encrypt);
winpr_Cipher_Free(rdp->fips_decrypt);
if (rdp->rc4_decrypt_key)
{
winpr_RC4_Free(rdp->rc4_decrypt_key);
rdp->rc4_decrypt_key = NULL;
}
if (rdp->rc4_encrypt_key)
{
winpr_RC4_Free(rdp->rc4_encrypt_key);
rdp->rc4_encrypt_key = NULL;
}
if (rdp->fips_encrypt)
{
winpr_Cipher_Free(rdp->fips_encrypt);
rdp->fips_encrypt = NULL;
}
if (rdp->fips_decrypt)
{
winpr_Cipher_Free(rdp->fips_decrypt);
rdp->fips_decrypt = NULL;
}
if (settings->ServerRandom)
{
free(settings->ServerRandom);
settings->ServerRandom = NULL;
settings->ServerRandomLength = 0;
}
if (settings->ServerCertificate)
{
free(settings->ServerCertificate);
settings->ServerCertificate = NULL;
}
if (settings->ClientAddress)
{
free(settings->ClientAddress);
settings->ClientAddress = NULL;
}
rdp->rc4_decrypt_key = NULL;
rdp->rc4_encrypt_key = NULL;
rdp->fips_encrypt = NULL;
rdp->fips_decrypt = NULL;
mcs_free(rdp->mcs);
rdp->mcs = NULL;
nego_free(rdp->nego);
rdp->nego = NULL;
license_free(rdp->license);
rdp->license = NULL;
transport_free(rdp->transport);
rdp->transport = NULL;
fastpath_free(rdp->fastpath);
rdp->mcs = NULL;
rdp->nego = NULL;
rdp->license = NULL;
rdp->transport = NULL;
rdp->fastpath = NULL;
}
BOOL rdp_reset(rdpRdp* rdp)
{
BOOL rc = TRUE;
rdpContext* context;
rdpSettings* settings;
WINPR_ASSERT(rdp);
context = rdp->context;
WINPR_ASSERT(context);
settings = rdp->settings;
WINPR_ASSERT(settings);
bulk_reset(rdp->bulk);
rdp_reset_free(rdp);
if (!freerdp_settings_set_pointer_len(settings, FreeRDP_ServerRandom, NULL, 0))
rc = FALSE;
if (!freerdp_settings_set_pointer_len(settings, FreeRDP_ServerCertificate, NULL, 0))
rc = FALSE;
if (!freerdp_settings_set_string(settings, FreeRDP_ClientAddress, NULL))
rc = FALSE;
if (!rc)
goto fail;
rc = FALSE;
rdp->transport = transport_new(context);
if (rdp->transport)
{
if (rdp->io)
transport_set_io_callbacks(rdp->transport, rdp->io);
if (!rdp->transport)
goto fail;
rdp->nego = nego_new(rdp->transport);
rdp->mcs = mcs_new(rdp->transport);
transport_set_layer(rdp->transport, TRANSPORT_LAYER_TCP);
if (rdp->io)
{
if (!transport_set_io_callbacks(rdp->transport, rdp->io))
goto fail;
}
rdp->nego = nego_new(rdp->transport);
if (!rdp->nego)
goto fail;
rdp->mcs = mcs_new(rdp->transport);
if (!rdp->mcs)
goto fail;
if (!transport_set_layer(rdp->transport, TRANSPORT_LAYER_TCP))
goto fail;
rdp->license = license_new(rdp);
if (!rdp->license)
goto fail;
rdp->fastpath = fastpath_new(rdp);
if (!rdp->fastpath)
goto fail;
rdp->errorInfo = 0;
rdp->deactivation_reactivation = 0;
rdp->finalize_sc_pdus = 0;
return rdp->transport && rdp->nego && rdp->mcs && rdp->fastpath && rdp->license;
rc = TRUE;
fail:
return rc;
}
/**
@ -1989,18 +2000,12 @@ void rdp_free(rdpRdp* rdp)
if (rdp)
{
DeleteCriticalSection(&rdp->critical);
winpr_RC4_Free(rdp->rc4_decrypt_key);
winpr_RC4_Free(rdp->rc4_encrypt_key);
winpr_Cipher_Free(rdp->fips_encrypt);
winpr_Cipher_Free(rdp->fips_decrypt);
rdp_reset_free(rdp);
freerdp_settings_free(rdp->settings);
transport_free(rdp->transport);
license_free(rdp->license);
input_free(rdp->input);
update_free(rdp->update);
fastpath_free(rdp->fastpath);
nego_free(rdp->nego);
mcs_free(rdp->mcs);
nla_free(rdp->nla);
redirection_free(rdp->redirection);
autodetect_free(rdp->autodetect);