mirror of
https://github.com/FreeRDP/FreeRDP.git
synced 2025-06-03 00:00:20 +00:00
Merge pull request #2636 from xhaakon/master
Fix crashes in shadow server
This commit is contained in:
commit
093aaa4dc0
@ -38,7 +38,7 @@ RemdeskClientContext* remdesk_get_client_interface(remdeskPlugin* remdesk)
|
|||||||
return pInterface;
|
return pInterface;
|
||||||
}
|
}
|
||||||
|
|
||||||
int remdesk_virtual_channel_write(remdeskPlugin* remdesk, wStream* s)
|
static int remdesk_virtual_channel_write(remdeskPlugin* remdesk, wStream* s)
|
||||||
{
|
{
|
||||||
UINT32 status = 0;
|
UINT32 status = 0;
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
#include "remdesk_main.h"
|
#include "remdesk_main.h"
|
||||||
|
|
||||||
int remdesk_virtual_channel_write(RemdeskServerContext* context, wStream* s)
|
static int remdesk_virtual_channel_write(RemdeskServerContext* context, wStream* s)
|
||||||
{
|
{
|
||||||
BOOL status;
|
BOOL status;
|
||||||
ULONG BytesWritten = 0;
|
ULONG BytesWritten = 0;
|
||||||
|
@ -145,6 +145,8 @@ BOOL WINAPI EnterSynchronizationBarrier(LPSYNCHRONIZATION_BARRIER lpBarrier, DWO
|
|||||||
status = TRUE;
|
status = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
InterlockedDecrement(&(pBarrier->count));
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,6 +167,9 @@ BOOL WINAPI DeleteSynchronizationBarrier(LPSYNCHRONIZATION_BARRIER lpBarrier)
|
|||||||
if (!pBarrier)
|
if (!pBarrier)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
|
while (InterlockedCompareExchange(&pBarrier->count, 0, 0) != 0)
|
||||||
|
Sleep(100);
|
||||||
|
|
||||||
CloseHandle(pBarrier->event);
|
CloseHandle(pBarrier->event);
|
||||||
|
|
||||||
free(pBarrier);
|
free(pBarrier);
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
#include <winpr/synch.h>
|
#include <winpr/synch.h>
|
||||||
#include <winpr/thread.h>
|
#include <winpr/thread.h>
|
||||||
|
|
||||||
|
#include "../synch.h"
|
||||||
|
|
||||||
static int g_Count;
|
static int g_Count;
|
||||||
static HANDLE g_Event;
|
static HANDLE g_Event;
|
||||||
static CRITICAL_SECTION g_Lock;
|
static CRITICAL_SECTION g_Lock;
|
||||||
@ -29,10 +31,19 @@ static void* test_synch_barrier_thread_func(void* arg)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void* barrier_deleter_thread_func(void* arg)
|
||||||
|
{
|
||||||
|
/* Blocks until all threads are released from the barrier. */
|
||||||
|
DeleteSynchronizationBarrier(&g_Barrier);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
int TestSynchBarrier(int argc, char* argv[])
|
int TestSynchBarrier(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
int index;
|
int index;
|
||||||
HANDLE threads[5];
|
HANDLE threads[5];
|
||||||
|
HANDLE deleter_thread = NULL;
|
||||||
|
|
||||||
g_Count = 0;
|
g_Count = 0;
|
||||||
|
|
||||||
@ -65,10 +76,30 @@ int TestSynchBarrier(int argc, char* argv[])
|
|||||||
printf("%s: CreateThread failed for thread #%d. GetLastError() = 0x%08x\n", __FUNCTION__, index, GetLastError());
|
printf("%s: CreateThread failed for thread #%d. GetLastError() = 0x%08x\n", __FUNCTION__, index, GetLastError());
|
||||||
while (index)
|
while (index)
|
||||||
CloseHandle(threads[--index]);
|
CloseHandle(threads[--index]);
|
||||||
|
CloseHandle(deleter_thread);
|
||||||
DeleteCriticalSection(&g_Lock);
|
DeleteCriticalSection(&g_Lock);
|
||||||
CloseHandle(g_Event);
|
CloseHandle(g_Event);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (index == 0)
|
||||||
|
{
|
||||||
|
/* Make sure first thread has already entered the barrier... */
|
||||||
|
while (((WINPR_BARRIER*) g_Barrier.Reserved3[0])->count == 0)
|
||||||
|
Sleep(100);
|
||||||
|
|
||||||
|
/* Now spawn the deleter thread. */
|
||||||
|
if (!(deleter_thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)
|
||||||
|
barrier_deleter_thread_func, NULL, 0, NULL)))
|
||||||
|
{
|
||||||
|
printf("%s: CreateThread failed for deleter thread. GetLastError() = 0x%08x\n", __FUNCTION__, GetLastError());
|
||||||
|
while (index)
|
||||||
|
CloseHandle(threads[--index]);
|
||||||
|
DeleteCriticalSection(&g_Lock);
|
||||||
|
CloseHandle(g_Event);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WaitForSingleObject(g_Event, INFINITE);
|
WaitForSingleObject(g_Event, INFINITE);
|
||||||
@ -83,7 +114,7 @@ int TestSynchBarrier(int argc, char* argv[])
|
|||||||
CloseHandle(threads[index]);
|
CloseHandle(threads[index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
DeleteSynchronizationBarrier(&g_Barrier);
|
CloseHandle(deleter_thread);
|
||||||
|
|
||||||
DeleteCriticalSection(&g_Lock);
|
DeleteCriticalSection(&g_Lock);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user