Merge pull request #7066 from akallabeth/rdpei_crash_fix

Stop rdpei thread before cleaning up listener
This commit is contained in:
David Fort 2021-05-31 13:19:44 +02:00 committed by GitHub
commit d76c8470b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 58 additions and 12 deletions

View File

@ -368,6 +368,9 @@ static UINT rdpei_send_pen_frame(RdpeiClientContext* context, RDPINPUT_PEN_FRAME
return ERROR_INTERNAL_ERROR;
callback = rdpei->listener_callback->channel_callback;
/* Just ignore the event if the channel is not connected */
if (!callback)
return CHANNEL_RC_OK;
if (!rdpei->previousPenFrameTime && !rdpei->currentPenFrameTime)
{
@ -872,6 +875,15 @@ static UINT rdpei_on_data_received(IWTSVirtualChannelCallback* pChannelCallback,
static UINT rdpei_on_close(IWTSVirtualChannelCallback* pChannelCallback)
{
RDPEI_CHANNEL_CALLBACK* callback = (RDPEI_CHANNEL_CALLBACK*)pChannelCallback;
if (callback)
{
RDPEI_PLUGIN* rdpei = (RDPEI_PLUGIN*)callback->plugin;
if (rdpei && rdpei->listener_callback)
{
if (rdpei->listener_callback->channel_callback == callback)
rdpei->listener_callback->channel_callback = NULL;
}
}
free(callback);
return CHANNEL_RC_OK;
}
@ -922,11 +934,9 @@ static UINT rdpei_plugin_terminated(IWTSPlugin* pPlugin)
if (!pPlugin)
return ERROR_INVALID_PARAMETER;
if (rdpei && rdpei->listener_callback)
if (rdpei)
{
IWTSVirtualChannelManager* mgr = rdpei->listener_callback->channel_mgr;
if (mgr)
IFCALL(mgr->DestroyListener, mgr, rdpei->listener);
IWTSVirtualChannelManager* mgr = NULL;
rdpei->initialized = FALSE;
if (rdpei->event)
@ -939,6 +949,12 @@ static UINT rdpei_plugin_terminated(IWTSPlugin* pPlugin)
}
if (rdpei->event)
CloseHandle(rdpei->event);
if (rdpei->listener_callback)
mgr = rdpei->listener_callback->channel_mgr;
if (mgr)
IFCALL(mgr->DestroyListener, mgr, rdpei->listener);
}
DeleteCriticalSection(&rdpei->lock);
free(rdpei->listener_callback);
@ -1026,11 +1042,16 @@ static UINT32 rdpei_get_features(RdpeiClientContext* context)
*/
UINT rdpei_send_frame(RdpeiClientContext* context, RDPINPUT_TOUCH_FRAME* frame)
{
UINT64 currentTime;
UINT64 currentTime = GetTickCount64();
RDPEI_PLUGIN* rdpei = (RDPEI_PLUGIN*)context->handle;
RDPEI_CHANNEL_CALLBACK* callback = rdpei->listener_callback->channel_callback;
RDPEI_CHANNEL_CALLBACK* callback;
UINT error;
currentTime = GetTickCount64();
callback = rdpei->listener_callback->channel_callback;
/* Just ignore the event if the channel is not connected */
if (!callback)
return CHANNEL_RC_OK;
if (!rdpei->previousFrameTime && !rdpei->currentFrameTime)
{

View File

@ -44,7 +44,7 @@ static DWORD WINAPI test_synch_barrier_thread(LPVOID lpParam)
for (i = 0; i < p->loops && gErrorCount == 0; i++)
{
/* simulate different execution times before the barrier */
Sleep(rand() % MAX_SLEEP_MS);
Sleep(1 + abs((rand() % MAX_SLEEP_MS)));
status = EnterSynchronizationBarrier(&gBarrier, p->flags);
// printf("Thread #%03u status: %s\n", tnum, status ? "TRUE" : "FALSE");
@ -182,6 +182,10 @@ int TestSynchBarrier(int argc, char* argv[])
DWORD dwMaxThreads;
DWORD dwMinThreads;
DWORD dwNumLoops = 200;
WINPR_UNUSED(argc);
WINPR_UNUSED(argv);
GetNativeSystemInfo(&sysinfo);
printf("%s: Number of processors: %" PRIu32 "\n", __FUNCTION__, sysinfo.dwNumberOfProcessors);
dwMinThreads = sysinfo.dwNumberOfProcessors;
@ -193,7 +197,8 @@ int TestSynchBarrier(int argc, char* argv[])
/* Test invalid parameters */
if (InitializeSynchronizationBarrier(&gBarrier, 0, -1))
{
printf(
fprintf(
stderr,
"%s: InitializeSynchronizationBarrier unecpectedly succeeded with lTotalThreads = 0\n",
__FUNCTION__);
return -1;
@ -201,7 +206,8 @@ int TestSynchBarrier(int argc, char* argv[])
if (InitializeSynchronizationBarrier(&gBarrier, -1, -1))
{
printf(
fprintf(
stderr,
"%s: InitializeSynchronizationBarrier unecpectedly succeeded with lTotalThreads = -1\n",
__FUNCTION__);
return -1;
@ -209,23 +215,42 @@ int TestSynchBarrier(int argc, char* argv[])
if (InitializeSynchronizationBarrier(&gBarrier, 1, -2))
{
printf("%s: InitializeSynchronizationBarrier unecpectedly succeeded with lSpinCount = -2\n",
__FUNCTION__);
fprintf(
stderr,
"%s: InitializeSynchronizationBarrier unecpectedly succeeded with lSpinCount = -2\n",
__FUNCTION__);
return -1;
}
/* Functional tests */
if (!TestSynchBarrierWithFlags(0, dwMaxThreads, dwNumLoops))
{
fprintf(stderr,
"%s: TestSynchBarrierWithFlags(0) unecpectedly succeeded with lTotalThreads = -1\n",
__FUNCTION__);
return -1;
}
if (!TestSynchBarrierWithFlags(SYNCHRONIZATION_BARRIER_FLAGS_SPIN_ONLY, dwMinThreads,
dwNumLoops))
{
fprintf(stderr,
"%s: TestSynchBarrierWithFlags(SYNCHRONIZATION_BARRIER_FLAGS_SPIN_ONLY) "
"unecpectedly succeeded with lTotalThreads = -1\n",
__FUNCTION__);
return -1;
}
if (!TestSynchBarrierWithFlags(SYNCHRONIZATION_BARRIER_FLAGS_BLOCK_ONLY, dwMaxThreads,
dwNumLoops))
{
fprintf(stderr,
"%s: TestSynchBarrierWithFlags(SYNCHRONIZATION_BARRIER_FLAGS_BLOCK_ONLY) "
"unecpectedly succeeded with lTotalThreads = -1\n",
__FUNCTION__);
return -1;
}
printf("%s: Test successfully completed\n", __FUNCTION__);
return 0;