mirror of https://github.com/FreeRDP/FreeRDP
Fix unchecked CreateThread calls and misc fixes
This commit is contained in:
parent
9a4f645f78
commit
25fc866a58
|
@ -472,7 +472,8 @@ static void* urbdrc_search_usb_device(void* arg)
|
|||
|
||||
/* Get the file descriptor (fd) for the monitor.
|
||||
This fd will get passed to select() */
|
||||
mon_fd = CreateFileDescriptorEvent(NULL, TRUE, FALSE, udev_monitor_get_fd(mon));
|
||||
if (!(mon_fd = CreateFileDescriptorEvent(NULL, TRUE, FALSE, udev_monitor_get_fd(mon))))
|
||||
goto fail_create_monfd_event;
|
||||
|
||||
while (1)
|
||||
{
|
||||
|
@ -651,6 +652,8 @@ static void* urbdrc_search_usb_device(void* arg)
|
|||
}
|
||||
|
||||
CloseHandle(mon_fd);
|
||||
|
||||
fail_create_monfd_event:
|
||||
sem_post(&searchman->sem_term);
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -339,10 +339,17 @@ static void* jni_input_thread(void* arg)
|
|||
|
||||
DEBUG_ANDROID("Start.");
|
||||
|
||||
queue = freerdp_get_message_queue(instance, FREERDP_INPUT_MESSAGE_QUEUE);
|
||||
event[0] = CreateFileDescriptorEvent(NULL, FALSE, FALSE, aCtx->event_queue->pipe_fd[0]);
|
||||
event[1] = CreateFileDescriptorEvent(NULL, FALSE, FALSE, aCtx->event_queue->pipe_fd[1]);
|
||||
event[2] = freerdp_get_message_queue_event_handle(instance, FREERDP_INPUT_MESSAGE_QUEUE);
|
||||
if (!(queue = freerdp_get_message_queue(instance, FREERDP_INPUT_MESSAGE_QUEUE)))
|
||||
goto fail_get_message_queue;
|
||||
|
||||
if (!(event[0] = CreateFileDescriptorEvent(NULL, FALSE, FALSE, aCtx->event_queue->pipe_fd[0])))
|
||||
goto fail_create_event_0;
|
||||
|
||||
if (!(event[1] = CreateFileDescriptorEvent(NULL, FALSE, FALSE, aCtx->event_queue->pipe_fd[1])))
|
||||
goto fail_create_event_1;
|
||||
|
||||
if (!(event[2] = freerdp_get_message_queue_event_handle(instance, FREERDP_INPUT_MESSAGE_QUEUE)))
|
||||
goto fail_get_message_queue_event;
|
||||
|
||||
do
|
||||
{
|
||||
|
@ -365,7 +372,14 @@ static void* jni_input_thread(void* arg)
|
|||
|
||||
DEBUG_ANDROID("Quit.");
|
||||
|
||||
fail_get_message_queue_event:
|
||||
CloseHandle(event[1]);
|
||||
fail_create_event_1:
|
||||
CloseHandle(event[0]);
|
||||
fail_create_event_0:
|
||||
MessageQueue_PostQuit(queue, 0);
|
||||
fail_get_message_queue:
|
||||
|
||||
ExitThread(0);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -416,8 +430,8 @@ static int android_freerdp_run(freerdp* instance)
|
|||
|
||||
const rdpSettings* settings = instance->context->settings;
|
||||
|
||||
HANDLE input_thread;
|
||||
HANDLE channels_thread;
|
||||
HANDLE input_thread = NULL;
|
||||
HANDLE channels_thread = NULL;
|
||||
|
||||
BOOL async_input = settings->AsyncInput;
|
||||
BOOL async_channels = settings->AsyncChannels;
|
||||
|
@ -439,14 +453,22 @@ static int android_freerdp_run(freerdp* instance)
|
|||
|
||||
if (async_input)
|
||||
{
|
||||
input_thread = CreateThread(NULL, 0,
|
||||
(LPTHREAD_START_ROUTINE) jni_input_thread, instance, 0, NULL);
|
||||
if (!(input_thread = CreateThread(NULL, 0,
|
||||
(LPTHREAD_START_ROUTINE) jni_input_thread, instance, 0, NULL)))
|
||||
{
|
||||
DEBUG_ANDROID("Failed to create async input thread\n");
|
||||
goto disconnect;
|
||||
}
|
||||
}
|
||||
|
||||
if (async_channels)
|
||||
{
|
||||
channels_thread = CreateThread(NULL, 0,
|
||||
(LPTHREAD_START_ROUTINE) jni_channels_thread, instance, 0, NULL);
|
||||
if (!(channels_thread = CreateThread(NULL, 0,
|
||||
(LPTHREAD_START_ROUTINE) jni_channels_thread, instance, 0, NULL)))
|
||||
{
|
||||
DEBUG_ANDROID("Failed to create async channels thread\n");
|
||||
goto disconnect;
|
||||
}
|
||||
}
|
||||
|
||||
((androidContext*)instance->context)->is_connected = TRUE;
|
||||
|
@ -568,6 +590,7 @@ static int android_freerdp_run(freerdp* instance)
|
|||
}
|
||||
}
|
||||
|
||||
disconnect:
|
||||
DEBUG_ANDROID("Prepare shutdown...");
|
||||
|
||||
// issue another OnDisconnecting here in case the disconnect was initiated by the server and not our client
|
||||
|
@ -578,17 +601,20 @@ static int android_freerdp_run(freerdp* instance)
|
|||
|
||||
DEBUG_ANDROID("Cleanup threads...");
|
||||
|
||||
if (async_channels)
|
||||
if (async_channels && channels_thread)
|
||||
{
|
||||
WaitForSingleObject(channels_thread, INFINITE);
|
||||
CloseHandle(channels_thread);
|
||||
}
|
||||
|
||||
if (async_input)
|
||||
if (async_input && input_thread)
|
||||
{
|
||||
wMessageQueue* input_queue = freerdp_get_message_queue(instance, FREERDP_INPUT_MESSAGE_QUEUE);
|
||||
MessageQueue_PostQuit(input_queue, 0);
|
||||
WaitForSingleObject(input_thread, INFINITE);
|
||||
if (input_queue)
|
||||
{
|
||||
MessageQueue_PostQuit(input_queue, 0);
|
||||
WaitForSingleObject(input_thread, INFINITE);
|
||||
}
|
||||
CloseHandle(input_thread);
|
||||
}
|
||||
|
||||
|
@ -670,8 +696,11 @@ JNIEXPORT jboolean JNICALL jni_freerdp_connect(JNIEnv *env, jclass cls, jint ins
|
|||
assert(inst);
|
||||
assert(ctx);
|
||||
|
||||
ctx->thread = CreateThread(NULL, 0,
|
||||
(LPTHREAD_START_ROUTINE)android_thread_func, inst, 0, NULL);
|
||||
if (!(ctx->thread = CreateThread(NULL, 0,
|
||||
(LPTHREAD_START_ROUTINE)android_thread_func, inst, 0, NULL)))
|
||||
{
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
|
|
@ -94,7 +94,11 @@ DWORD mac_client_thread(void* param);
|
|||
mfc->client_height = instance->settings->DesktopHeight;
|
||||
mfc->client_width = instance->settings->DesktopWidth;
|
||||
|
||||
mfc->thread = CreateThread(NULL, 0, mac_client_thread, (void*) context, 0, &mfc->mainThreadId);
|
||||
if (!(mfc->thread = CreateThread(NULL, 0, mac_client_thread, (void*) context, 0, &mfc->mainThreadId)))
|
||||
{
|
||||
WLog_ERR(TAG, "failed to create client thread");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -162,9 +166,9 @@ DWORD mac_client_thread(void* param)
|
|||
int status;
|
||||
HANDLE events[4];
|
||||
HANDLE inputEvent;
|
||||
HANDLE inputThread;
|
||||
HANDLE inputThread = NULL;
|
||||
HANDLE updateEvent;
|
||||
HANDLE updateThread;
|
||||
HANDLE updateThread = NULL;
|
||||
HANDLE channelsEvent;
|
||||
|
||||
DWORD nCount;
|
||||
|
@ -190,7 +194,11 @@ DWORD mac_client_thread(void* param)
|
|||
|
||||
if (settings->AsyncUpdate)
|
||||
{
|
||||
updateThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) mac_client_update_thread, context, 0, NULL);
|
||||
if (!(updateThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) mac_client_update_thread, context, 0, NULL)))
|
||||
{
|
||||
WLog_ERR(TAG, "failed to create async update thread");
|
||||
goto disconnect;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -199,7 +207,11 @@ DWORD mac_client_thread(void* param)
|
|||
|
||||
if (settings->AsyncInput)
|
||||
{
|
||||
inputThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) mac_client_input_thread, context, 0, NULL);
|
||||
if (!(inputThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) mac_client_input_thread, context, 0, NULL)))
|
||||
{
|
||||
WLog_ERR(TAG, "failed to create async input thread");
|
||||
goto disconnect;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -214,7 +226,6 @@ DWORD mac_client_thread(void* param)
|
|||
|
||||
if (WaitForSingleObject(mfc->stopEvent, 0) == WAIT_OBJECT_0)
|
||||
{
|
||||
freerdp_disconnect(instance);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -240,19 +251,29 @@ DWORD mac_client_thread(void* param)
|
|||
}
|
||||
}
|
||||
|
||||
if (settings->AsyncUpdate)
|
||||
disconnect:
|
||||
|
||||
freerdp_disconnect(instance);
|
||||
|
||||
if (settings->AsyncUpdate && updateThread)
|
||||
{
|
||||
wMessageQueue* updateQueue = freerdp_get_message_queue(instance, FREERDP_UPDATE_MESSAGE_QUEUE);
|
||||
MessageQueue_PostQuit(updateQueue, 0);
|
||||
WaitForSingleObject(updateThread, INFINITE);
|
||||
if (updateQueue)
|
||||
{
|
||||
MessageQueue_PostQuit(updateQueue, 0);
|
||||
WaitForSingleObject(updateThread, INFINITE);
|
||||
}
|
||||
CloseHandle(updateThread);
|
||||
}
|
||||
|
||||
if (settings->AsyncInput)
|
||||
if (settings->AsyncInput && inputThread)
|
||||
{
|
||||
wMessageQueue* inputQueue = freerdp_get_message_queue(instance, FREERDP_INPUT_MESSAGE_QUEUE);
|
||||
MessageQueue_PostQuit(inputQueue, 0);
|
||||
WaitForSingleObject(inputThread, INFINITE);
|
||||
if (inputQueue)
|
||||
{
|
||||
MessageQueue_PostQuit(inputQueue, 0);
|
||||
WaitForSingleObject(inputThread, INFINITE);
|
||||
}
|
||||
CloseHandle(inputThread);
|
||||
}
|
||||
|
||||
|
|
|
@ -54,9 +54,7 @@ int mfreerdp_client_start(rdpContext* context)
|
|||
}
|
||||
|
||||
view = (MRDPView*) mfc->view;
|
||||
[view rdpStart:context];
|
||||
|
||||
return 0;
|
||||
return [view rdpStart:context];
|
||||
}
|
||||
|
||||
int mfreerdp_client_stop(rdpContext* context)
|
||||
|
@ -82,7 +80,7 @@ int mfreerdp_client_stop(rdpContext* context)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int mfreerdp_client_new(freerdp* instance, rdpContext* context)
|
||||
BOOL mfreerdp_client_new(freerdp* instance, rdpContext* context)
|
||||
{
|
||||
mfContext* mfc;
|
||||
rdpSettings* settings;
|
||||
|
@ -103,7 +101,7 @@ int mfreerdp_client_new(freerdp* instance, rdpContext* context)
|
|||
settings->AsyncUpdate = TRUE;
|
||||
settings->AsyncInput = TRUE;
|
||||
|
||||
return 0;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void mfreerdp_client_free(freerdp* instance, rdpContext* context)
|
||||
|
|
|
@ -203,10 +203,16 @@ int main(int argc, char* argv[])
|
|||
|
||||
freerdp_client_load_addins(instance->context->channels, instance->settings);
|
||||
|
||||
thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)
|
||||
tf_client_thread_proc, instance, 0, NULL);
|
||||
if (!(thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)
|
||||
tf_client_thread_proc, instance, 0, NULL)))
|
||||
{
|
||||
WLog_ERR(TAG, "Failed to create client thread");
|
||||
}
|
||||
else
|
||||
{
|
||||
WaitForSingleObject(thread, INFINITE);
|
||||
}
|
||||
|
||||
WaitForSingleObject(thread, INFINITE);
|
||||
freerdp_context_free(instance);
|
||||
freerdp_free(instance);
|
||||
|
||||
|
|
|
@ -670,9 +670,13 @@ DWORD WINAPI wf_client_thread(LPVOID lpParam)
|
|||
|
||||
if (async_input)
|
||||
{
|
||||
input_thread = CreateThread(NULL, 0,
|
||||
if (!(input_thread = CreateThread(NULL, 0,
|
||||
(LPTHREAD_START_ROUTINE) wf_input_thread,
|
||||
instance, 0, NULL);
|
||||
instance, 0, NULL)))
|
||||
{
|
||||
WLog_ERR(TAG, "Failed to create async input thread.");
|
||||
goto disconnect;
|
||||
}
|
||||
}
|
||||
|
||||
while (1)
|
||||
|
@ -771,6 +775,7 @@ DWORD WINAPI wf_client_thread(LPVOID lpParam)
|
|||
CloseHandle(input_thread);
|
||||
}
|
||||
|
||||
disconnect:
|
||||
freerdp_disconnect(instance);
|
||||
WLog_DBG(TAG, "Main thread exited.");
|
||||
|
||||
|
|
|
@ -1417,10 +1417,9 @@ void* xf_client_thread(void* param)
|
|||
/* Connection succeeded. --authonly ? */
|
||||
if (instance->settings->AuthenticationOnly || !status)
|
||||
{
|
||||
freerdp_disconnect(instance);
|
||||
WLog_ERR(TAG, "Authentication only, exit status %d", !status);
|
||||
exit_code = XF_EXIT_CONN_FAILED;
|
||||
ExitThread(exit_code);
|
||||
goto disconnect;
|
||||
}
|
||||
|
||||
channels = context->channels;
|
||||
|
@ -1432,8 +1431,18 @@ void* xf_client_thread(void* param)
|
|||
}
|
||||
else
|
||||
{
|
||||
inputThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) xf_input_thread, instance, 0, NULL);
|
||||
inputEvent = freerdp_get_message_queue_event_handle(instance, FREERDP_INPUT_MESSAGE_QUEUE);
|
||||
if (!(inputEvent = freerdp_get_message_queue_event_handle(instance, FREERDP_INPUT_MESSAGE_QUEUE)))
|
||||
{
|
||||
WLog_ERR(TAG, "async input: failed to get input event handle");
|
||||
exit_code = XF_EXIT_UNKNOWN;
|
||||
goto disconnect;
|
||||
}
|
||||
if (!(inputThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) xf_input_thread, instance, 0, NULL)))
|
||||
{
|
||||
WLog_ERR(TAG, "async input: failed to create input thread");
|
||||
exit_code = XF_EXIT_UNKNOWN;
|
||||
goto disconnect;
|
||||
}
|
||||
}
|
||||
|
||||
while (!xfc->disconnect && !freerdp_shall_disconnect(instance))
|
||||
|
@ -1512,8 +1521,8 @@ void* xf_client_thread(void* param)
|
|||
if (!exit_code)
|
||||
exit_code = freerdp_error_info(instance);
|
||||
|
||||
disconnect:
|
||||
freerdp_disconnect(instance);
|
||||
|
||||
ExitThread(exit_code);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1623,9 +1632,13 @@ static int xfreerdp_client_start(rdpContext* context)
|
|||
|
||||
xfc->disconnect = FALSE;
|
||||
|
||||
xfc->thread = CreateThread(NULL, 0,
|
||||
if (!(xfc->thread = CreateThread(NULL, 0,
|
||||
(LPTHREAD_START_ROUTINE) xf_client_thread,
|
||||
context->instance, 0, NULL);
|
||||
context->instance, 0, NULL)))
|
||||
{
|
||||
WLog_ERR(TAG, "failed to create client thread");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -316,7 +316,8 @@ RFX_CONTEXT* rfx_context_new(BOOL encoder)
|
|||
SetThreadpoolCallbackPool(&priv->ThreadPoolEnv, priv->ThreadPool);
|
||||
|
||||
if (priv->MinThreadCount)
|
||||
SetThreadpoolThreadMinimum(priv->ThreadPool, priv->MinThreadCount);
|
||||
if (!SetThreadpoolThreadMinimum(priv->ThreadPool, priv->MinThreadCount))
|
||||
goto error_threadPool_minimum;
|
||||
|
||||
if (priv->MaxThreadCount)
|
||||
SetThreadpoolThreadMaximum(priv->ThreadPool, priv->MaxThreadCount);
|
||||
|
@ -339,6 +340,8 @@ RFX_CONTEXT* rfx_context_new(BOOL encoder)
|
|||
context->state = RFX_STATE_SEND_HEADERS;
|
||||
return context;
|
||||
|
||||
error_threadPool_minimum:
|
||||
CloseThreadpool(priv->ThreadPool);
|
||||
error_threadPool:
|
||||
BufferPool_Free(priv->BufferPool);
|
||||
error_BufferPool:
|
||||
|
|
|
@ -111,9 +111,7 @@ BOOL freerdp_connect(freerdp* instance)
|
|||
|
||||
IFCALLRET(instance->PostConnect, status, instance);
|
||||
|
||||
update_post_connect(instance->update);
|
||||
|
||||
if (!status)
|
||||
if (!status || !update_post_connect(instance->update))
|
||||
{
|
||||
WLog_ERR(TAG, "freerdp_post_connect failed");
|
||||
|
||||
|
|
|
@ -180,6 +180,7 @@ static BOOL freerdp_listener_open_local(freerdp_listener* instance, const char*
|
|||
int sockfd;
|
||||
struct sockaddr_un addr;
|
||||
rdpListener* listener = (rdpListener*) instance->listener;
|
||||
HANDLE hevent;
|
||||
|
||||
sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
|
||||
|
@ -213,8 +214,15 @@ static BOOL freerdp_listener_open_local(freerdp_listener* instance, const char*
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
if (!(hevent = CreateFileDescriptorEvent(NULL, FALSE, FALSE, sockfd)))
|
||||
{
|
||||
WLog_ERR(TAG, "failed to create sockfd event");
|
||||
closesocket((SOCKET) sockfd);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
listener->sockfds[listener->num_sockfds] = sockfd;
|
||||
listener->events[listener->num_sockfds] = CreateFileDescriptorEvent(NULL, FALSE, FALSE, sockfd);
|
||||
listener->events[listener->num_sockfds] = hevent;
|
||||
listener->num_sockfds++;
|
||||
WLog_INFO(TAG, "Listening on socket %s.", addr.sun_path);
|
||||
return TRUE;
|
||||
|
|
|
@ -2546,15 +2546,17 @@ static void *update_message_proxy_thread(void *arg)
|
|||
rdpUpdateProxy *update_message_proxy_new(rdpUpdate *update)
|
||||
{
|
||||
rdpUpdateProxy *message;
|
||||
message = (rdpUpdateProxy *) malloc(sizeof(rdpUpdateProxy));
|
||||
|
||||
if (message)
|
||||
if (!(message = (rdpUpdateProxy *) calloc(1, sizeof(rdpUpdateProxy))))
|
||||
return NULL;
|
||||
|
||||
message->update = update;
|
||||
update_message_register_interface(message, update);
|
||||
if (!(message->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) update_message_proxy_thread, update, 0, NULL)))
|
||||
{
|
||||
ZeroMemory(message, sizeof(rdpUpdateProxy));
|
||||
|
||||
message->update = update;
|
||||
update_message_register_interface(message, update);
|
||||
message->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) update_message_proxy_thread, update, 0, NULL);
|
||||
WLog_ERR(TAG, "Failed to create proxy thread");
|
||||
free(message);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return message;
|
||||
|
|
|
@ -572,17 +572,20 @@ void update_reset_state(rdpUpdate* update)
|
|||
}
|
||||
}
|
||||
|
||||
void update_post_connect(rdpUpdate* update)
|
||||
BOOL update_post_connect(rdpUpdate* update)
|
||||
{
|
||||
update->asynchronous = update->context->settings->AsyncUpdate;
|
||||
|
||||
if (update->asynchronous)
|
||||
update->proxy = update_message_proxy_new(update);
|
||||
if (!(update->proxy = update_message_proxy_new(update)))
|
||||
return FALSE;
|
||||
|
||||
update->altsec->switch_surface.bitmapId = SCREEN_BITMAP_SURFACE;
|
||||
IFCALL(update->altsec->SwitchSurface, update->context, &(update->altsec->switch_surface));
|
||||
|
||||
update->initialState = FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void update_post_disconnect(rdpUpdate* update)
|
||||
|
|
|
@ -43,7 +43,7 @@ void update_free(rdpUpdate* update);
|
|||
void update_free_bitmap(BITMAP_UPDATE* bitmap_update);
|
||||
|
||||
void update_reset_state(rdpUpdate* update);
|
||||
void update_post_connect(rdpUpdate* update);
|
||||
BOOL update_post_connect(rdpUpdate* update);
|
||||
void update_post_disconnect(rdpUpdate* update);
|
||||
|
||||
BOOL update_read_bitmap_update(rdpUpdate* update, wStream* s, BITMAP_UPDATE* bitmapUpdate);
|
||||
|
|
|
@ -446,7 +446,8 @@ static void* tf_debug_channel_thread_func(void* arg)
|
|||
fd = *((void**) buffer);
|
||||
WTSFreeMemory(buffer);
|
||||
|
||||
context->event = CreateWaitObjectEvent(NULL, TRUE, FALSE, fd);
|
||||
if (!(context->event = CreateWaitObjectEvent(NULL, TRUE, FALSE, fd)))
|
||||
return NULL;
|
||||
}
|
||||
|
||||
s = Stream_New(NULL, 4096);
|
||||
|
@ -779,14 +780,13 @@ static void* test_peer_mainloop(void* arg)
|
|||
|
||||
static BOOL test_peer_accepted(freerdp_listener* instance, freerdp_peer* client)
|
||||
{
|
||||
HANDLE hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) test_peer_mainloop, (void*) client, 0, NULL);
|
||||
HANDLE hThread;
|
||||
|
||||
if (hThread != NULL) {
|
||||
CloseHandle(hThread);
|
||||
return TRUE;
|
||||
}
|
||||
if (!(hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) test_peer_mainloop, (void*) client, 0, NULL)))
|
||||
return FALSE;
|
||||
|
||||
return FALSE;
|
||||
CloseHandle(hThread);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void test_server_mainloop(freerdp_listener* instance)
|
||||
|
|
|
@ -33,6 +33,7 @@ int wf_directsound_activate(RdpsndServerContext* context)
|
|||
{
|
||||
HRESULT hr;
|
||||
wfInfo* wfi;
|
||||
HANDLE hThread;
|
||||
|
||||
LPDIRECTSOUNDCAPTUREBUFFER pDSCB;
|
||||
|
||||
|
@ -77,7 +78,12 @@ int wf_directsound_activate(RdpsndServerContext* context)
|
|||
pDSCB->lpVtbl->Release(pDSCB);
|
||||
lastPos = 0;
|
||||
|
||||
CreateThread(NULL, 0, wf_rdpsnd_directsound_thread, latestPeer, 0, NULL);
|
||||
if (!(hThread = CreateThread(NULL, 0, wf_rdpsnd_directsound_thread, latestPeer, 0, NULL)))
|
||||
{
|
||||
WLog_ERR(TAG, "Failed to create direct sound thread");
|
||||
return 1;
|
||||
}
|
||||
CloseHandle(hThread);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -156,13 +156,13 @@ BOOL wfreerdp_server_start(wfServer* server)
|
|||
|
||||
wf_settings_read_dword(HKEY_LOCAL_MACHINE, _T("Software\\FreeRDP\\Server"), _T("DefaultPort"), &server->port);
|
||||
|
||||
if (instance->Open(instance, NULL, (UINT16) server->port))
|
||||
{
|
||||
server->thread = CreateThread(NULL, 0, wf_server_main_loop, (void*) instance, 0, NULL);
|
||||
return TRUE;
|
||||
}
|
||||
if (!instance->Open(instance, NULL, (UINT16) server->port))
|
||||
return FALSE;
|
||||
|
||||
return FALSE;
|
||||
if (!(server->thread = CreateThread(NULL, 0, wf_server_main_loop, (void*) instance, 0, NULL)))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL wfreerdp_server_stop(wfServer* server)
|
||||
|
|
|
@ -151,9 +151,12 @@ void wf_peer_synchronize_event(rdpInput* input, UINT32 flags)
|
|||
|
||||
BOOL wf_peer_accepted(freerdp_listener* instance, freerdp_peer* client)
|
||||
{
|
||||
if (!CreateThread(NULL, 0, wf_peer_main_loop, client, 0, NULL))
|
||||
HANDLE hThread;
|
||||
|
||||
if (!(hThread = CreateThread(NULL, 0, wf_peer_main_loop, client, 0, NULL)))
|
||||
return FALSE;
|
||||
|
||||
CloseHandle(hThread);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ int wf_rdpsnd_set_latest_peer(wfPeerContext* peer)
|
|||
int wf_wasapi_activate(RdpsndServerContext* context)
|
||||
{
|
||||
wchar_t * pattern = L"Stereo Mix";
|
||||
HANDLE hThread;
|
||||
|
||||
wf_wasapi_get_device_string(pattern, &devStr);
|
||||
|
||||
|
@ -46,7 +47,12 @@ int wf_wasapi_activate(RdpsndServerContext* context)
|
|||
}
|
||||
|
||||
WLog_DBG(TAG, "RDPSND (WASAPI) Activated");
|
||||
CreateThread(NULL, 0, wf_rdpsnd_wasapi_thread, latestPeer, 0, NULL);
|
||||
if (!(hThread = CreateThread(NULL, 0, wf_rdpsnd_wasapi_thread, latestPeer, 0, NULL)))
|
||||
{
|
||||
WLog_ERR(TAG, "CreateThread failed");
|
||||
return 1;
|
||||
}
|
||||
CloseHandle(hThread);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
#include <freerdp/codec/color.h>
|
||||
#include <freerdp/codec/region.h>
|
||||
#include <freerdp/log.h>
|
||||
|
||||
#include "../shadow_screen.h"
|
||||
#include "../shadow_client.h"
|
||||
|
@ -33,6 +34,9 @@
|
|||
|
||||
#include "mac_shadow.h"
|
||||
|
||||
#define TAG SERVER_TAG("shadow.mac")
|
||||
|
||||
|
||||
static macShadowSubsystem* g_Subsystem = NULL;
|
||||
|
||||
void mac_shadow_input_synchronize_event(macShadowSubsystem* subsystem, UINT32 flags)
|
||||
|
@ -616,9 +620,13 @@ int mac_shadow_subsystem_start(macShadowSubsystem* subsystem)
|
|||
|
||||
mac_shadow_capture_start(subsystem);
|
||||
|
||||
thread = CreateThread(NULL, 0,
|
||||
if (!(thread = CreateThread(NULL, 0,
|
||||
(LPTHREAD_START_ROUTINE) mac_shadow_subsystem_thread,
|
||||
(void*) subsystem, 0, NULL);
|
||||
(void*) subsystem, 0, NULL)))
|
||||
{
|
||||
WLog_ERR(TAG, "Failed to create thread");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -269,9 +269,13 @@ int shw_freerdp_client_start(rdpContext* context)
|
|||
|
||||
shw = (shwContext*) context;
|
||||
|
||||
shw->thread = CreateThread(NULL, 0,
|
||||
if (!(shw->thread = CreateThread(NULL, 0,
|
||||
(LPTHREAD_START_ROUTINE) shw_client_thread,
|
||||
instance, 0, NULL);
|
||||
instance, 0, NULL)))
|
||||
{
|
||||
WLog_ERR(TAG, "Failed to create thread");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -485,9 +485,13 @@ int win_shadow_subsystem_start(winShadowSubsystem* subsystem)
|
|||
if (!subsystem)
|
||||
return -1;
|
||||
|
||||
thread = CreateThread(NULL, 0,
|
||||
if (!(thread = CreateThread(NULL, 0,
|
||||
(LPTHREAD_START_ROUTINE) win_shadow_subsystem_thread,
|
||||
(void*) subsystem, 0, NULL);
|
||||
(void*) subsystem, 0, NULL)))
|
||||
{
|
||||
WLog_ERR(TAG, "Failed to create thread");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -1236,7 +1236,8 @@ int x11_shadow_subsystem_init(x11ShadowSubsystem* subsystem)
|
|||
subsystem->use_xdamage = FALSE;
|
||||
}
|
||||
|
||||
subsystem->event = CreateFileDescriptorEvent(NULL, FALSE, FALSE, subsystem->xfds);
|
||||
if (!(subsystem->event = CreateFileDescriptorEvent(NULL, FALSE, FALSE, subsystem->xfds)))
|
||||
return -1;
|
||||
|
||||
virtualScreen = &(subsystem->virtualScreen);
|
||||
|
||||
|
@ -1283,9 +1284,13 @@ int x11_shadow_subsystem_start(x11ShadowSubsystem* subsystem)
|
|||
if (!subsystem)
|
||||
return -1;
|
||||
|
||||
subsystem->thread = CreateThread(NULL, 0,
|
||||
if (!(subsystem->thread = CreateThread(NULL, 0,
|
||||
(LPTHREAD_START_ROUTINE) x11_shadow_subsystem_thread,
|
||||
(void*) subsystem, 0, NULL);
|
||||
(void*) subsystem, 0, NULL)))
|
||||
{
|
||||
WLog_ERR(TAG, "Failed to create thread");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -1087,8 +1087,12 @@ BOOL shadow_client_accepted(freerdp_listener* listener, freerdp_peer* peer)
|
|||
|
||||
client = (rdpShadowClient*) peer->context;
|
||||
|
||||
client->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)
|
||||
shadow_client_thread, client, 0, NULL);
|
||||
if (!(client->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)
|
||||
shadow_client_thread, client, 0, NULL)))
|
||||
{
|
||||
freerdp_peer_context_free(peer);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
@ -376,10 +376,13 @@ int shadow_server_start(rdpShadowServer* server)
|
|||
else
|
||||
status = server->listener->OpenLocal(server->listener, server->ipcSocket);
|
||||
|
||||
if (status)
|
||||
if (!status)
|
||||
return -1;
|
||||
|
||||
if (!(server->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)
|
||||
shadow_server_thread, (void*) server, 0, NULL)))
|
||||
{
|
||||
server->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)
|
||||
shadow_server_thread, (void*) server, 0, NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -60,6 +60,7 @@ int TestErrorSetLastError(int argc, char* argv[])
|
|||
{
|
||||
DWORD error;
|
||||
HANDLE threads[4];
|
||||
int i;
|
||||
|
||||
/* We must initialize WLog here. It will check for settings
|
||||
* in the environment and if the variables are not set, the last
|
||||
|
@ -85,10 +86,14 @@ int TestErrorSetLastError(int argc, char* argv[])
|
|||
}
|
||||
*pLoopCount = 0;
|
||||
|
||||
threads[0] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) test_error_thread, (void*) (size_t) 0, 0, NULL);
|
||||
threads[1] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) test_error_thread, (void*) (size_t) 1, 0, NULL);
|
||||
threads[2] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) test_error_thread, (void*) (size_t) 2, 0, NULL);
|
||||
threads[3] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) test_error_thread, (void*) (size_t) 3, 0, NULL);
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
if (!(threads[i] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) test_error_thread, (void*) (size_t) 0, 0, NULL)))
|
||||
{
|
||||
printf("Failed to create thread #%d\n", i);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// let the threads run for at least 2 seconds
|
||||
Sleep(2000);
|
||||
|
|
|
@ -252,9 +252,12 @@ BOOL SetThreadpoolThreadMinimum(PTP_POOL ptpp, DWORD cthrdMic)
|
|||
|
||||
while (ArrayList_Count(ptpp->Threads) < ptpp->Minimum)
|
||||
{
|
||||
thread = CreateThread(NULL, 0,
|
||||
if (!(thread = CreateThread(NULL, 0,
|
||||
(LPTHREAD_START_ROUTINE) thread_pool_work_func,
|
||||
(void*) ptpp, 0, NULL);
|
||||
(void*) ptpp, 0, NULL)))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
ArrayList_Add(ptpp->Threads, thread);
|
||||
}
|
||||
|
|
|
@ -24,7 +24,12 @@ int TestPoolThread(int argc, char* argv[])
|
|||
return -1;
|
||||
}
|
||||
|
||||
SetThreadpoolThreadMinimum(pool, 8); /* default is 0 */
|
||||
if (!SetThreadpoolThreadMinimum(pool, 8)) /* default is 0 */
|
||||
{
|
||||
printf("SetThreadpoolThreadMinimum failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
SetThreadpoolThreadMaximum(pool, 64); /* default is 500 */
|
||||
|
||||
CloseThreadpool(pool);
|
||||
|
|
|
@ -64,7 +64,12 @@ int TestPoolWork(int argc, char* argv[])
|
|||
return -1;
|
||||
}
|
||||
|
||||
SetThreadpoolThreadMinimum(pool, 4);
|
||||
if (!SetThreadpoolThreadMinimum(pool, 4))
|
||||
{
|
||||
printf("SetThreadpoolThreadMinimum failure\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
SetThreadpoolThreadMaximum(pool, 8);
|
||||
|
||||
InitializeThreadpoolEnvironment(&environment);
|
||||
|
|
|
@ -627,7 +627,12 @@ int TestSchannel(int argc, char* argv[])
|
|||
return -1;
|
||||
}
|
||||
|
||||
thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) schannel_test_server_thread, NULL, 0, NULL);
|
||||
if (!(thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) schannel_test_server_thread, NULL, 0, NULL)))
|
||||
{
|
||||
printf("Failed to create server thread\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
table = InitSecurityInterface();
|
||||
status = QuerySecurityPackageInfo(SCHANNEL_NAME, &pPackageInfo);
|
||||
|
||||
|
|
|
@ -59,8 +59,16 @@ int TestSynchBarrier(int argc, char* argv[])
|
|||
|
||||
for (index = 0; index < 5; index++)
|
||||
{
|
||||
threads[index] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)
|
||||
test_synch_barrier_thread_func, NULL, 0, NULL);
|
||||
if (!(threads[index] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)
|
||||
test_synch_barrier_thread_func, NULL, 0, NULL)))
|
||||
{
|
||||
printf("%s: CreateThread failed for thread #%d. GetLastError() = 0x%08x\n", __FUNCTION__, index, GetLastError());
|
||||
while (index)
|
||||
CloseHandle(threads[--index]);
|
||||
DeleteCriticalSection(&g_Lock);
|
||||
CloseHandle(g_Event);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
WaitForSingleObject(g_Event, INFINITE);
|
||||
|
|
|
@ -217,8 +217,13 @@ static PVOID TestSynchCritical_Main(PVOID arg)
|
|||
|
||||
/* the TestSynchCritical_Test1 threads shall run until bTest1Running is FALSE */
|
||||
bTest1Running = TRUE;
|
||||
for (i = 0; i < (int) dwThreadCount; i++) {
|
||||
hThreads[i] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) TestSynchCritical_Test1, &bTest1Running, 0, NULL);
|
||||
for (i = 0; i < (int) dwThreadCount; i++)
|
||||
{
|
||||
if (!(hThreads[i] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) TestSynchCritical_Test1, &bTest1Running, 0, NULL)))
|
||||
{
|
||||
printf("CriticalSection failure: Failed to create test_1 thread #%d\n", i);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
/* let it run for TEST_SYNC_CRITICAL_TEST1_RUNTIME_MS ... */
|
||||
|
@ -265,7 +270,11 @@ static PVOID TestSynchCritical_Main(PVOID arg)
|
|||
goto fail;
|
||||
}
|
||||
/* This thread tries to call TryEnterCriticalSection which must fail */
|
||||
hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) TestSynchCritical_Test2, NULL, 0, NULL);
|
||||
if (!(hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) TestSynchCritical_Test2, NULL, 0, NULL)))
|
||||
{
|
||||
printf("CriticalSection failure: Failed to create test_2 thread\n");
|
||||
goto fail;
|
||||
}
|
||||
if (WaitForSingleObject(hThread, INFINITE) != WAIT_OBJECT_0)
|
||||
{
|
||||
printf("CriticalSection failure: Failed to wait for thread\n");
|
||||
|
@ -300,7 +309,11 @@ int TestSynchCritical(int argc, char* argv[])
|
|||
|
||||
printf("Deadlock will be assumed after %u ms.\n", dwDeadLockDetectionTimeMs);
|
||||
|
||||
hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) TestSynchCritical_Main, &bThreadTerminated, 0, NULL);
|
||||
if (!(hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) TestSynchCritical_Main, &bThreadTerminated, 0, NULL)))
|
||||
{
|
||||
printf("CriticalSection failure: Failed to create main thread\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* We have to be able to detect dead locks in this test.
|
||||
|
|
|
@ -65,17 +65,41 @@ static void* message_echo_pipe_server_thread(void* arg)
|
|||
|
||||
int TestMessagePipe(int argc, char* argv[])
|
||||
{
|
||||
HANDLE ClientThread;
|
||||
HANDLE ServerThread;
|
||||
wMessagePipe* EchoPipe;
|
||||
HANDLE ClientThread = NULL;
|
||||
HANDLE ServerThread = NULL;
|
||||
wMessagePipe* EchoPipe = NULL;
|
||||
int ret = 1;
|
||||
|
||||
EchoPipe = MessagePipe_New();
|
||||
if (!(EchoPipe = MessagePipe_New()))
|
||||
{
|
||||
printf("failed to create message pipe\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
ClientThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) message_echo_pipe_client_thread, (void*) EchoPipe, 0, NULL);
|
||||
ServerThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) message_echo_pipe_server_thread, (void*) EchoPipe, 0, NULL);
|
||||
if (!(ClientThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) message_echo_pipe_client_thread, (void*) EchoPipe, 0, NULL)))
|
||||
{
|
||||
printf("failed to create client thread\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!(ServerThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) message_echo_pipe_server_thread, (void*) EchoPipe, 0, NULL)))
|
||||
{
|
||||
printf("failed to create server thread\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
WaitForSingleObject(ClientThread, INFINITE);
|
||||
WaitForSingleObject(ServerThread, INFINITE);
|
||||
|
||||
return 0;
|
||||
ret = 0;
|
||||
|
||||
out:
|
||||
if (EchoPipe)
|
||||
MessagePipe_Free(EchoPipe);
|
||||
if (ClientThread)
|
||||
CloseHandle(ClientThread);
|
||||
if (ServerThread)
|
||||
CloseHandle(ServerThread);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -29,9 +29,18 @@ int TestMessageQueue(int argc, char* argv[])
|
|||
HANDLE thread;
|
||||
wMessageQueue* queue;
|
||||
|
||||
queue = MessageQueue_New(NULL);
|
||||
if (!(queue = MessageQueue_New(NULL)))
|
||||
{
|
||||
printf("failed to create message queue\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) message_queue_consumer_thread, (void*) queue, 0, NULL);
|
||||
if (!(thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) message_queue_consumer_thread, (void*) queue, 0, NULL)))
|
||||
{
|
||||
printf("failed to create thread\n");
|
||||
MessageQueue_Free(queue);
|
||||
return 1;
|
||||
}
|
||||
|
||||
MessageQueue_Post(queue, NULL, 123, NULL, NULL);
|
||||
MessageQueue_Post(queue, NULL, 456, NULL, NULL);
|
||||
|
@ -41,6 +50,7 @@ int TestMessageQueue(int argc, char* argv[])
|
|||
WaitForSingleObject(thread, INFINITE);
|
||||
|
||||
MessageQueue_Free(queue);
|
||||
CloseHandle(thread);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue