/* 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)
{
}
CloseHandle(mon_fd);
+
+fail_create_monfd_event:
sem_post(&searchman->sem_term);
return 0;
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
{
while(1);
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;
}
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;
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;
}
}
+disconnect:
DEBUG_ANDROID("Prepare shutdown...");
// issue another OnDisconnecting here in case the disconnect was initiated by the server and not our client
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);
}
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;
}
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;
}
int status;
HANDLE events[4];
HANDLE inputEvent;
- HANDLE inputThread;
+ HANDLE inputThread = NULL;
HANDLE updateEvent;
- HANDLE updateThread;
+ HANDLE updateThread = NULL;
HANDLE channelsEvent;
DWORD nCount;
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
{
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
{
if (WaitForSingleObject(mfc->stopEvent, 0) == WAIT_OBJECT_0)
{
- freerdp_disconnect(instance);
break;
}
}
}
- 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);
}
}
view = (MRDPView*) mfc->view;
- [view rdpStart:context];
-
- return 0;
+ return [view rdpStart:context];
}
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;
settings->AsyncUpdate = TRUE;
settings->AsyncInput = TRUE;
- return 0;
+ return TRUE;
}
void mfreerdp_client_free(freerdp* instance, rdpContext* context)
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);
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)
CloseHandle(input_thread);
}
+disconnect:
freerdp_disconnect(instance);
WLog_DBG(TAG, "Main thread exited.");
/* 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;
}
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))
if (!exit_code)
exit_code = freerdp_error_info(instance);
+disconnect:
freerdp_disconnect(instance);
-
ExitThread(exit_code);
return NULL;
}
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;
}
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);
context->state = RFX_STATE_SEND_HEADERS;
return context;
+error_threadPool_minimum:
+ CloseThreadpool(priv->ThreadPool);
error_threadPool:
BufferPool_Free(priv->BufferPool);
error_BufferPool:
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");
int sockfd;
struct sockaddr_un addr;
rdpListener* listener = (rdpListener*) instance->listener;
+ HANDLE hevent;
sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
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;
rdpUpdateProxy *update_message_proxy_new(rdpUpdate *update)
{
rdpUpdateProxy *message;
- message = (rdpUpdateProxy *) malloc(sizeof(rdpUpdateProxy));
- if (message)
- {
- ZeroMemory(message, sizeof(rdpUpdateProxy));
+ if (!(message = (rdpUpdateProxy *) calloc(1, sizeof(rdpUpdateProxy))))
+ return NULL;
- message->update = update;
- update_message_register_interface(message, update);
- message->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) update_message_proxy_thread, update, 0, 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)))
+ {
+ WLog_ERR(TAG, "Failed to create proxy thread");
+ free(message);
+ return NULL;
}
return message;
}
}
-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)
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);
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);
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)
{
HRESULT hr;
wfInfo* wfi;
+ HANDLE hThread;
LPDIRECTSOUNDCAPTUREBUFFER pDSCB;
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;
}
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)
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;
}
int wf_wasapi_activate(RdpsndServerContext* context)
{
wchar_t * pattern = L"Stereo Mix";
+ HANDLE hThread;
wf_wasapi_get_device_string(pattern, &devStr);
}
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;
}
#include <freerdp/codec/color.h>
#include <freerdp/codec/region.h>
+#include <freerdp/log.h>
#include "../shadow_screen.h"
#include "../shadow_client.h"
#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)
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;
}
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;
}
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;
}
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);
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;
}
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;
}
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;
{
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
}
*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);
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);
}
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);
return -1;
}
- SetThreadpoolThreadMinimum(pool, 4);
+ if (!SetThreadpoolThreadMinimum(pool, 4))
+ {
+ printf("SetThreadpoolThreadMinimum failure\n");
+ return -1;
+ }
+
SetThreadpoolThreadMaximum(pool, 8);
InitializeThreadpoolEnvironment(&environment);
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);
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);
/* 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 ... */
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");
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.
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;
}
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);
WaitForSingleObject(thread, INFINITE);
MessageQueue_Free(queue);
+ CloseHandle(thread);
return 0;
}