Unified rdpsnd cleanup code (#7697)

This commit is contained in:
akallabeth 2022-03-04 09:55:37 +01:00 committed by GitHub
parent 3d38d2636c
commit 37421b6614
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1230,6 +1230,25 @@ fail:
return CHANNEL_RC_NO_MEMORY;
}
static void cleanup_internals(rdpsndPlugin* rdpsnd)
{
if (!rdpsnd)
return;
if (rdpsnd->pool)
StreamPool_Return(rdpsnd->pool, rdpsnd->data_in);
audio_formats_free(rdpsnd->ClientFormats, rdpsnd->NumberOfClientFormats);
audio_formats_free(rdpsnd->ServerFormats, rdpsnd->NumberOfServerFormats);
rdpsnd->NumberOfClientFormats = 0;
rdpsnd->ClientFormats = NULL;
rdpsnd->NumberOfServerFormats = 0;
rdpsnd->ServerFormats = NULL;
rdpsnd->data_in = NULL;
}
/**
* Function description
*
@ -1259,15 +1278,7 @@ static UINT rdpsnd_virtual_channel_event_disconnected(rdpsndPlugin* rdpsnd)
}
if (rdpsnd->pool)
StreamPool_Return(rdpsnd->pool, rdpsnd->data_in);
audio_formats_free(rdpsnd->ClientFormats, rdpsnd->NumberOfClientFormats);
rdpsnd->NumberOfClientFormats = 0;
rdpsnd->ClientFormats = NULL;
audio_formats_free(rdpsnd->ServerFormats, rdpsnd->NumberOfServerFormats);
rdpsnd->NumberOfServerFormats = 0;
rdpsnd->ServerFormats = NULL;
cleanup_internals(rdpsnd);
if (rdpsnd->device)
{
@ -1584,17 +1595,8 @@ static UINT rdpsnd_on_close(IWTSVirtualChannelCallback* pChannelCallback)
if (rdpsnd->device)
IFCALL(rdpsnd->device->Close, rdpsnd->device);
if (rdpsnd->pool)
{
StreamPool_Return(rdpsnd->pool, rdpsnd->data_in);
}
cleanup_internals(rdpsnd);
audio_formats_free(rdpsnd->ClientFormats, rdpsnd->NumberOfClientFormats);
rdpsnd->NumberOfClientFormats = 0;
rdpsnd->ClientFormats = NULL;
audio_formats_free(rdpsnd->ServerFormats, rdpsnd->NumberOfServerFormats);
rdpsnd->NumberOfServerFormats = 0;
rdpsnd->ServerFormats = NULL;
if (rdpsnd->device)
{
IFCALL(rdpsnd->device->Free, rdpsnd->device);