/* 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;
}
setlocale(LC_ALL, "");
- g_sem = CreateSemaphore(NULL, 0, 1, NULL);
+ if (!(g_sem = CreateSemaphore(NULL, 0, 1, NULL)))
+ {
+ WLog_ERR(TAG, "Failed to create semaphore");
+ exit(1);
+ }
instance = freerdp_new();
instance->PreConnect = df_pre_connect;
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);
wlfWindow* window;
wlfContext* context;
- gdi_init(instance, CLRCONV_ALPHA | CLRCONV_INVERT | CLRBUF_32BPP, NULL);
+ gdi_init(instance, CLRCONV_ALPHA | CLRBUF_32BPP, NULL);
gdi = instance->context->gdi;
if (!gdi)
return FALSE;
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.");
XFreeModifiermap(xfc->modifierMap);
xfc->modifierMap = XGetModifierMapping(xfc->display);
- assert(!xfc->gc);
- xfc->gc = XCreateGC(xfc->display, xfc->drawable, GCGraphicsExposures, &gcv);
- assert(!xfc->primary);
- xfc->primary = XCreatePixmap(xfc->display, xfc->drawable, xfc->sessionWidth, xfc->sessionHeight, xfc->depth);
+ if (!xfc->gc);
+ xfc->gc = XCreateGC(xfc->display, xfc->drawable, GCGraphicsExposures, &gcv);
+ if (!xfc->primary);
+ xfc->primary = XCreatePixmap(xfc->display, xfc->drawable, xfc->sessionWidth, xfc->sessionHeight, xfc->depth);
xfc->drawing = xfc->primary;
- assert(!xfc->bitmap_mono);
- xfc->bitmap_mono = XCreatePixmap(xfc->display, xfc->drawable, 8, 8, 1);
- assert(!xfc->gc_mono);
- xfc->gc_mono = XCreateGC(xfc->display, xfc->bitmap_mono, GCGraphicsExposures, &gcv);
+ if (!xfc->bitmap_mono);
+ xfc->bitmap_mono = XCreatePixmap(xfc->display, xfc->drawable, 8, 8, 1);
+ if (!xfc->gc_mono);
+ xfc->gc_mono = XCreateGC(xfc->display, xfc->bitmap_mono, GCGraphicsExposures, &gcv);
XSetFunction(xfc->display, xfc->gc, GXcopy);
XSetFillStyle(xfc->display, xfc->gc, FillSolid);
XSetForeground(xfc->display, xfc->gc, BlackPixelOfScreen(xfc->screen));
XFillRectangle(xfc->display, xfc->primary, xfc->gc, 0, 0, xfc->sessionWidth, xfc->sessionHeight);
XFlush(xfc->display);
- assert(!xfc->image);
-
- xfc->image = XCreateImage(xfc->display, xfc->visual, xfc->depth, ZPixmap, 0,
+ if (!xfc->image);
+ xfc->image = XCreateImage(xfc->display, xfc->visual, xfc->depth, ZPixmap, 0,
(char*) xfc->primary_buffer, xfc->sessionWidth, xfc->sessionHeight, xfc->scanline_pad, 0);
return TRUE;
/* 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;
}
typedef BOOL (*psListenerOpen)(freerdp_listener* instance, const char* bind_address, UINT16 port);
typedef BOOL (*psListenerOpenLocal)(freerdp_listener* instance, const char* path);
+typedef BOOL (*psListenerOpenFromSocket)(freerdp_listener* instance, int fd);
typedef BOOL (*psListenerGetFileDescriptor)(freerdp_listener* instance, void** rfds, int* rcount);
typedef DWORD (*psListenerGetEventHandles)(freerdp_listener* instance, HANDLE* events, DWORD nCount);
typedef BOOL (*psListenerCheckFileDescriptor)(freerdp_listener* instance);
psListenerClose Close;
psPeerAccepted PeerAccepted;
+ psListenerOpenFromSocket OpenFromSocket;
};
FREERDP_API freerdp_listener* freerdp_listener_new(void);
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:
if (fastpath->fragmentation != -1)
{
WLog_ERR(TAG, "Unexpected FASTPATH_FRAGMENT_SINGLE");
- return -1;
+ goto out_fail;
}
totalSize = size;
status = fastpath_recv_update(fastpath, updateCode, totalSize, cs);
if (status < 0)
- return -1;
+ goto out_fail;
}
else
{
if (fastpath->fragmentation != -1)
{
WLog_ERR(TAG, "Unexpected FASTPATH_FRAGMENT_FIRST");
- return -1;
+ goto out_fail;
}
fastpath->fragmentation = FASTPATH_FRAGMENT_FIRST;
{
WLog_ERR(TAG, "Total size (%d) exceeds MultifragMaxRequestSize (%d)",
totalSize, transport->settings->MultifragMaxRequestSize);
- return -1;
+ goto out_fail;
}
if (!(fastpath->updateData = StreamPool_Take(transport->ReceivePool, size)))
- return -1;
+ goto out_fail;
Stream_SetPosition(fastpath->updateData, 0);
(fastpath->fragmentation != FASTPATH_FRAGMENT_NEXT))
{
WLog_ERR(TAG, "Unexpected FASTPATH_FRAGMENT_NEXT");
- return -1;
+ goto out_fail;
}
fastpath->fragmentation = FASTPATH_FRAGMENT_NEXT;
{
WLog_ERR(TAG, "Total size (%d) exceeds MultifragMaxRequestSize (%d)",
totalSize, transport->settings->MultifragMaxRequestSize);
- return -1;
+ goto out_fail;
}
if (!Stream_EnsureCapacity(fastpath->updateData, totalSize))
{
WLog_ERR(TAG, "Couldn't re-allocate memory for stream");
- return -1;
+ goto out_fail;
}
Stream_Copy(fastpath->updateData, cs, size);
(fastpath->fragmentation != FASTPATH_FRAGMENT_NEXT))
{
WLog_ERR(TAG, "Unexpected FASTPATH_FRAGMENT_LAST");
- return -1;
+ goto out_fail;
}
fastpath->fragmentation = -1;
{
WLog_ERR(TAG, "Total size (%d) exceeds MultifragMaxRequestSize (%d)",
totalSize, transport->settings->MultifragMaxRequestSize);
- return -1;
+ goto out_fail;
}
if (!Stream_EnsureCapacity(fastpath->updateData, totalSize))
{
WLog_ERR(TAG, "Couldn't re-allocate memory for stream");
- return -1;
+ goto out_fail;
}
Stream_Copy(fastpath->updateData, cs, size);
Stream_Release(fastpath->updateData);
if (status < 0)
- return -1;
+ goto out_fail;
}
}
Stream_Release(cs);
return status;
+
+out_fail:
+
+ if (cs != s) {
+ Stream_Release(cs);
+ }
+
+ return -1;
}
int fastpath_recv_updates(rdpFastPath* fastpath, wStream* s)
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");
if ((ai->ai_family != AF_INET) && (ai->ai_family != AF_INET6))
continue;
+ if (listener->num_sockfds == MAX_LISTENER_HANDLES)
+ {
+ WLog_ERR(TAG, "too many listening sockets");
+ continue;
+ }
+
sockfd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
if (sockfd == -1)
int sockfd;
struct sockaddr_un addr;
rdpListener* listener = (rdpListener*) instance->listener;
+ HANDLE hevent;
+
+ if (listener->num_sockfds == MAX_LISTENER_HANDLES)
+ {
+ WLog_ERR(TAG, "too many listening sockets");
+ return FALSE;
+ }
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;
#endif
}
+static BOOL freerdp_listener_open_from_socket(freerdp_listener* instance, int fd)
+{
+#ifndef _WIN32
+ rdpListener* listener = (rdpListener*) instance->listener;
+
+ if (listener->num_sockfds == MAX_LISTENER_HANDLES)
+ {
+ WLog_ERR(TAG, "too many listening sockets");
+ return FALSE;
+ }
+
+ if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0)
+ return FALSE;
+
+ listener->sockfds[listener->num_sockfds] = fd;
+ listener->events[listener->num_sockfds] = CreateFileDescriptorEvent(NULL, FALSE, FALSE, fd);
+ if (!listener->events[listener->num_sockfds])
+ return FALSE;
+
+ listener->num_sockfds++;
+
+ WLog_INFO(TAG, "Listening on socket %d.", fd);
+ return TRUE;
+#else
+ return FALSE;
+#endif
+
+
+}
+
static void freerdp_listener_close(freerdp_listener* instance)
{
int i;
instance->Open = freerdp_listener_open;
instance->OpenLocal = freerdp_listener_open_local;
+ instance->OpenFromSocket = freerdp_listener_open_from_socket;
instance->GetFileDescriptor = freerdp_listener_get_fds;
instance->GetEventHandles = freerdp_listener_get_event_handles;
instance->CheckFileDescriptor = freerdp_listener_check_fds;
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;
{
case DATA_PDU_TYPE_UPDATE:
if (!update_recv(rdp->update, cs))
- return -1;
+ goto out_fail;
break;
case DATA_PDU_TYPE_CONTROL:
if (!rdp_recv_server_control_pdu(rdp, cs))
- return -1;
+ goto out_fail;
break;
case DATA_PDU_TYPE_POINTER:
if (!update_recv_pointer(rdp->update, cs))
- return -1;
+ goto out_fail;
break;
case DATA_PDU_TYPE_SYNCHRONIZE:
if (!rdp_recv_synchronize_pdu(rdp, cs))
- return -1;
+ goto out_fail;
break;
case DATA_PDU_TYPE_PLAY_SOUND:
if (!update_recv_play_sound(rdp->update, cs))
- return -1;
+ goto out_fail;
break;
case DATA_PDU_TYPE_SHUTDOWN_DENIED:
if (!rdp_recv_server_shutdown_denied_pdu(rdp, cs))
- return -1;
+ goto out_fail;
break;
case DATA_PDU_TYPE_SAVE_SESSION_INFO:
if (!rdp_recv_save_session_info(rdp, cs))
- return -1;
+ goto out_fail;
break;
case DATA_PDU_TYPE_FONT_MAP:
if (!rdp_recv_font_map_pdu(rdp, cs))
- return -1;
+ goto out_fail;
break;
case DATA_PDU_TYPE_SET_KEYBOARD_INDICATORS:
if (!rdp_recv_server_set_keyboard_indicators_pdu(rdp, cs))
- return -1;
+ goto out_fail;
break;
case DATA_PDU_TYPE_SET_KEYBOARD_IME_STATUS:
if (!rdp_recv_server_set_keyboard_ime_status_pdu(rdp, cs))
- return -1;
+ goto out_fail;
break;
case DATA_PDU_TYPE_SET_ERROR_INFO:
if (!rdp_recv_set_error_info_data_pdu(rdp, cs))
- return -1;
+ goto out_fail;
break;
case DATA_PDU_TYPE_ARC_STATUS:
if (!rdp_recv_server_auto_reconnect_status_pdu(rdp, cs))
- return -1;
+ goto out_fail;
break;
case DATA_PDU_TYPE_STATUS_INFO:
if (!rdp_recv_server_status_info_pdu(rdp, cs))
- return -1;
+ goto out_fail;
break;
case DATA_PDU_TYPE_MONITOR_LAYOUT:
if (!rdp_recv_monitor_layout_pdu(rdp, cs))
- return -1;
+ goto out_fail;
break;
default:
Stream_Release(cs);
return 0;
+
+out_fail:
+ if (cs != s)
+ Stream_Release(cs);
+ return -1;
}
int rdp_recv_message_channel_pdu(rdpRdp* rdp, wStream* s)
rdpContext* context = transport->context;
rdpSettings* settings = transport->settings;
+ if (!(tls = tls_new(settings)))
+ return FALSE;
+
+ transport->tls = tls;
+
if (transport->GatewayEnabled)
- {
- tls = transport->tls = tls_new(settings);
transport->layer = TRANSPORT_LAYER_TSG_TLS;
- }
else
- {
- tls = transport->tls = tls_new(settings);
transport->layer = TRANSPORT_LAYER_TLS;
- }
-
- transport->tls = tls;
tls->hostname = settings->ServerHostname;
tls->port = settings->ServerPort;
}
}
-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);
if (Stream_GetRemainingLength(s) < new_len)
return FALSE;
+ if (!new_len)
+ {
+ free(unicode_string->string);
+ unicode_string->string = NULL;
+ unicode_string->length = 0;
+ return TRUE;
+ }
+
new_str = (BYTE*) realloc(unicode_string->string, new_len);
if (!new_str)
{
#define TAG FREERDP_TAG("crypto")
-int certificate_store_init(rdpCertificateStore* certificate_store)
+BOOL certificate_store_init(rdpCertificateStore* certificate_store)
{
- char* server_path;
+ char* server_path = NULL;
rdpSettings* settings;
settings = certificate_store->settings;
if (!PathFileExistsA(settings->ConfigPath))
{
- CreateDirectoryA(settings->ConfigPath, 0);
+ if (!CreateDirectoryA(settings->ConfigPath, 0))
+ {
+ WLog_ERR(TAG, "error creating directory '%s'", settings->ConfigPath);
+ goto fail;
+ }
WLog_INFO(TAG, "creating directory %s", settings->ConfigPath);
}
- certificate_store->path = GetCombinedPath(settings->ConfigPath, (char*) certificate_store_dir);
-
- if (!certificate_store->path)
- return -1;
+ if (!(certificate_store->path = GetCombinedPath(settings->ConfigPath, (char*) certificate_store_dir)))
+ goto fail;
if (!PathFileExistsA(certificate_store->path))
{
- CreateDirectoryA(certificate_store->path, 0);
- WLog_INFO(TAG, "creating directory %s", certificate_store->path);
+ if (!CreateDirectoryA(certificate_store->path, 0))
+ {
+ WLog_ERR(TAG, "error creating directory [%s]", certificate_store->path);
+ goto fail;
+ }
+ WLog_INFO(TAG, "creating directory [%s]", certificate_store->path);
}
- server_path = GetCombinedPath(settings->ConfigPath, (char*) certificate_server_dir);
-
- if (!server_path)
- return -1;
+ if (!(server_path = GetCombinedPath(settings->ConfigPath, (char*) certificate_server_dir)))
+ goto fail;
if (!PathFileExistsA(server_path))
{
- CreateDirectoryA(server_path, 0);
- WLog_INFO(TAG, "creating directory %s", server_path);
+ if (!CreateDirectoryA(server_path, 0))
+ {
+ WLog_ERR(TAG, "error creating directory [%s]", server_path);
+ goto fail;
+ }
+ WLog_INFO(TAG, "created directory [%s]", server_path);
}
- free(server_path);
-
- certificate_store->file = GetCombinedPath(settings->ConfigPath, (char*) certificate_known_hosts_file);
-
- if (!certificate_store->file)
- return -1;
+ if (!(certificate_store->file = GetCombinedPath(settings->ConfigPath, (char*) certificate_known_hosts_file)))
+ goto fail;
- if (PathFileExistsA(certificate_store->file) == FALSE)
- {
+ if (!PathFileExistsA(certificate_store->file))
certificate_store->fp = fopen((char*) certificate_store->file, "w+");
-
- if (!certificate_store->fp)
- {
- WLog_ERR(TAG, "certificate_store_open: error opening [%s] for writing", certificate_store->file);
- return -1;
- }
-
- fflush(certificate_store->fp);
- }
else
- {
certificate_store->fp = fopen((char*) certificate_store->file, "r+");
+
+ if (!certificate_store->fp)
+ {
+ WLog_ERR(TAG, "error opening [%s]", certificate_store->file);
+ goto fail;
}
- return 1;
+ free(server_path);
+
+ return TRUE;
+
+fail:
+ WLog_ERR(TAG, "certificate store initialization failed");
+ free(server_path);
+ free(certificate_store->path);
+ free(certificate_store->file);
+ certificate_store->path = NULL;
+ certificate_store->file = NULL;
+ return FALSE;
}
int certificate_data_match(rdpCertificateStore* certificate_store, rdpCertificateData* certificate_data)
certificate_store->settings = settings;
- certificate_store_init(certificate_store);
+ if (!certificate_store_init(certificate_store))
+ {
+ free(certificate_store);
+ return NULL;
+ }
return certificate_store;
}
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;
}
BOOL wf_peer_rdpsnd_init(wfPeerContext* context)
{
- wfInfo* wfi;
+ wfInfo* wfi = wf_info_get_instance();
- wfi = wf_info_get_instance();
+ if (!wfi)
+ return FALSE;
+
+ if (!(wfi->snd_mutex = CreateMutex(NULL, FALSE, NULL)))
+ return FALSE;
- wfi->snd_mutex = CreateMutex(NULL, FALSE, NULL);
context->rdpsnd = rdpsnd_server_context_new(context->vcm);
context->rdpsnd->data = context;
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;
if (userLibraryPath)
{
- if (!PathFileExistsA(userLibraryPath))
- CreateDirectoryA(userLibraryPath, 0);
+ if (!PathFileExistsA(userLibraryPath) &&
+ !CreateDirectoryA(userLibraryPath, 0))
+ {
+ WLog_ERR(TAG, "Failed to create directory '%s'", userLibraryPath);
+ free(userLibraryPath);
+ return -1;
+ }
userApplicationSupportPath = GetCombinedPath(userLibraryPath, "Application Support");
if (userApplicationSupportPath)
{
- if (!PathFileExistsA(userApplicationSupportPath))
- CreateDirectoryA(userApplicationSupportPath, 0);
-
+ if (!PathFileExistsA(userApplicationSupportPath) &&
+ !CreateDirectoryA(userApplicationSupportPath, 0))
+ {
+ WLog_ERR(TAG, "Failed to create directory '%s'", userApplicationSupportPath);
+ free(userLibraryPath);
+ free(userApplicationSupportPath);
+ return -1;
+ }
server->ConfigPath = GetCombinedPath(userApplicationSupportPath, "freerdp");
}
if (configHome)
{
- if (!PathFileExistsA(configHome))
- CreateDirectoryA(configHome, 0);
-
+ if (!PathFileExistsA(configHome) &&
+ !CreateDirectoryA(configHome, 0))
+ {
+ WLog_ERR(TAG, "Failed to create directory '%s'", configHome);
+ free(configHome);
+ return -1;
+ }
server->ConfigPath = GetKnownSubPath(KNOWN_PATH_XDG_CONFIG_HOME, "freerdp");
-
free(configHome);
}
}
int makecert_argc = (sizeof(makecert_argv) / sizeof(char*));
- if (!PathFileExistsA(server->ConfigPath))
- CreateDirectoryA(server->ConfigPath, 0);
-
- filepath = GetCombinedPath(server->ConfigPath, "shadow");
+ if (!PathFileExistsA(server->ConfigPath) &&
+ !CreateDirectoryA(server->ConfigPath, 0))
+ {
+ WLog_ERR(TAG, "Failed to create directory '%s'", server->ConfigPath);
+ return -1;
+ }
- if (!filepath)
+ if (!(filepath = GetCombinedPath(server->ConfigPath, "shadow")))
return -1;
- if (!PathFileExistsA(filepath))
- CreateDirectoryA(filepath, 0);
+ if (!PathFileExistsA(filepath) &&
+ !CreateDirectoryA(filepath, 0))
+ {
+ WLog_ERR(TAG, "Failed to create directory '%s'", filepath);
+ free(filepath);
+ return -1;
+ }
server->CertificateFile = GetCombinedPath(filepath, "shadow.crt");
server->PrivateKeyFile = GetCombinedPath(filepath, "shadow.key");
#define BitStream_Prefetch(_bs) do { \
(_bs->prefetch) = 0; \
- if (((UINT32) (_bs->pointer - _bs->buffer)) < (_bs->capacity + 4)) \
+ if (((UINT32) (_bs->pointer - _bs->buffer) + 4) < (_bs->capacity)) \
(_bs->prefetch) |= (*(_bs->pointer + 4) << 24); \
- if (((UINT32) (_bs->pointer - _bs->buffer)) < (_bs->capacity + 5)) \
+ if (((UINT32) (_bs->pointer - _bs->buffer) + 5) < (_bs->capacity)) \
(_bs->prefetch) |= (*(_bs->pointer + 5) << 16); \
- if (((UINT32) (_bs->pointer - _bs->buffer)) < (_bs->capacity + 6)) \
+ if (((UINT32) (_bs->pointer - _bs->buffer) + 6) < (_bs->capacity)) \
(_bs->prefetch) |= (*(_bs->pointer + 6) << 8); \
- if (((UINT32) (_bs->pointer - _bs->buffer)) < (_bs->capacity + 7)) \
+ if (((UINT32) (_bs->pointer - _bs->buffer) + 7) < (_bs->capacity)) \
(_bs->prefetch) |= (*(_bs->pointer + 7) << 0); \
} while(0)
#define BitStream_Fetch(_bs) do { \
(_bs->accumulator) = 0; \
- if (((UINT32) (_bs->pointer - _bs->buffer)) < (_bs->capacity + 0)) \
+ if (((UINT32) (_bs->pointer - _bs->buffer) + 0) < (_bs->capacity)) \
(_bs->accumulator) |= (*(_bs->pointer + 0) << 24); \
- if (((UINT32) (_bs->pointer - _bs->buffer)) < (_bs->capacity + 1)) \
+ if (((UINT32) (_bs->pointer - _bs->buffer) + 1) < (_bs->capacity)) \
(_bs->accumulator) |= (*(_bs->pointer + 1) << 16); \
- if (((UINT32) (_bs->pointer - _bs->buffer)) < (_bs->capacity + 2)) \
+ if (((UINT32) (_bs->pointer - _bs->buffer) + 2) < (_bs->capacity)) \
(_bs->accumulator) |= (*(_bs->pointer + 2) << 8); \
- if (((UINT32) (_bs->pointer - _bs->buffer)) <(_bs->capacity + 3)) \
+ if (((UINT32) (_bs->pointer - _bs->buffer) + 3) <(_bs->capacity)) \
(_bs->accumulator) |= (*(_bs->pointer + 3) << 0); \
BitStream_Prefetch(_bs); \
} while(0)
#define BitStream_Flush(_bs) do { \
- if (((UINT32) (_bs->pointer - _bs->buffer)) < (_bs->capacity + 0)) \
+ if (((UINT32) (_bs->pointer - _bs->buffer) + 0) < (_bs->capacity)) \
*(_bs->pointer + 0) = (_bs->accumulator >> 24); \
- if (((UINT32) (_bs->pointer - _bs->buffer)) < (_bs->capacity + 1)) \
+ if (((UINT32) (_bs->pointer - _bs->buffer) + 1) < (_bs->capacity)) \
*(_bs->pointer + 1) = (_bs->accumulator >> 16); \
- if (((UINT32) (_bs->pointer - _bs->buffer)) < (_bs->capacity + 2)) \
+ if (((UINT32) (_bs->pointer - _bs->buffer) + 2) < (_bs->capacity)) \
*(_bs->pointer + 2) = (_bs->accumulator >> 8); \
- if (((UINT32) (_bs->pointer - _bs->buffer)) < (_bs->capacity + 3)) \
+ if (((UINT32) (_bs->pointer - _bs->buffer) + 3) < (_bs->capacity)) \
*(_bs->pointer + 3) = (_bs->accumulator >> 0); \
} while(0)
WLOG_APPENDER_COMMON();
};
-#define WLOG_CONSOLE_STDOUT 1
-#define WLOG_CONSOLE_STDERR 2
-#define WLOG_CONSOLE_DEBUG 3
+#define WLOG_CONSOLE_DEFAULT 0
+#define WLOG_CONSOLE_STDOUT 1
+#define WLOG_CONSOLE_STDERR 2
+#define WLOG_CONSOLE_DEBUG 4
struct _wLogConsoleAppender
{
{
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);
static volatile HANDLE mutex = NULL;
-int static_mutex_lock(volatile HANDLE* static_mutex)
+BOOL static_mutex_lock(volatile HANDLE* static_mutex)
{
if (*static_mutex == NULL)
{
- HANDLE handle = CreateMutex(NULL, FALSE, NULL);
+ HANDLE handle;
+
+ if (!(handle = CreateMutex(NULL, FALSE, NULL)))
+ return FALSE;
if (InterlockedCompareExchangePointer((PVOID*) static_mutex, (PVOID) handle, NULL) != NULL)
CloseHandle(handle);
}
- return (WaitForSingleObject(*static_mutex, INFINITE) == WAIT_FAILED);
+ return (WaitForSingleObject(*static_mutex, INFINITE) == WAIT_OBJECT_0);
}
LONGLONG InterlockedCompareExchange64(LONGLONG volatile *Destination, LONGLONG Exchange, LONGLONG Comperand)
{
LONGLONG previousValue = 0;
-
- static_mutex_lock(&mutex);
+ BOOL locked = static_mutex_lock(&mutex);
previousValue = *Destination;
if (*Destination == Comperand)
*Destination = Exchange;
- ReleaseMutex(mutex);
+ if (locked)
+ ReleaseMutex(mutex);
+ else
+ fprintf(stderr, "WARNING: InterlockedCompareExchange64 operation might have failed\n");
return previousValue;
}
if (!PathFileExistsA(lpPipePath))
{
- CreateDirectoryA(lpPipePath, 0);
+ if (!CreateDirectoryA(lpPipePath, 0))
+ {
+ free(lpPipePath);
+ goto out;
+ }
UnixChangeFileMode(lpPipePath, 0xFFFF);
}
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);
if (g_Log)
return;
- g_Log = WLog_Get("WinSCard");
+ if (!PathFileExistsA(filepath))
+ if (!CreateDirectoryA(filepath, NULL))
+ return;
+
+ if (!(g_Log = WLog_Get("WinSCard")))
+ return;
WLog_SetLogLevel(g_Log, WLOG_DEBUG);
WLog_SetLogAppenderType(g_Log, WLOG_APPENDER_FILE);
appender = (wLogFileAppender*) WLog_GetLogAppender(g_Log);
- if (!PathFileExistsA(filepath))
- CreateDirectoryA(filepath, NULL);
-
WLog_FileAppender_SetOutputFileName(g_Log, appender, "WinSCard.txt");
WLog_FileAppender_SetOutputFilePath(g_Log, appender, filepath);
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.
&StartupInfo,
&ProcessInformation);
+ if (!status)
+ {
+ printf("CreateProcess failed. error=%d\n", GetLastError());
+ return 1;
+ }
+
FreeEnvironmentStrings(lpszEnvironmentBlock);
WaitForSingleObject(ProcessInformation.hProcess, INFINITE);
static struct CRYPTO_dynlock_value* _winpr_openssl_dynlock_create(const char* file, int line)
{
- struct CRYPTO_dynlock_value* dynlock = (struct CRYPTO_dynlock_value*)
- malloc(sizeof(struct CRYPTO_dynlock_value));
+ struct CRYPTO_dynlock_value* dynlock;
- if (dynlock)
+ if (!(dynlock = (struct CRYPTO_dynlock_value*) malloc(sizeof(struct CRYPTO_dynlock_value))))
+ return NULL;
+
+ if (!(dynlock->mutex = CreateMutex(NULL, FALSE, NULL)))
{
- dynlock->mutex = CreateMutex(NULL, FALSE, NULL);
+ free(dynlock);
+ return NULL;
}
return dynlock;
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;
}
if (!PathFileExistsA(appender->FilePath))
{
- CreateDirectoryA(appender->FilePath, 0);
+ if (!CreateDirectoryA(appender->FilePath, 0))
+ return -1;
UnixChangeFileMode(appender->FilePath, 0xFFFF);
}
return;
if (outputStream < 0)
- outputStream = WLOG_CONSOLE_STDOUT;
+ outputStream = WLOG_CONSOLE_DEFAULT;
if (outputStream == WLOG_CONSOLE_STDOUT)
appender->outputStream = WLOG_CONSOLE_STDOUT;
else if (outputStream == WLOG_CONSOLE_STDERR)
appender->outputStream = WLOG_CONSOLE_STDERR;
else
- appender->outputStream = WLOG_CONSOLE_STDOUT;
+ appender->outputStream = WLOG_CONSOLE_DEFAULT;
}
int WLog_ConsoleAppender_Open(wLog* log, wLogConsoleAppender* appender)
__android_log_print(level, log->Name, "%s%s", message->PrefixString, message->TextString);
#else
- fp = (appender->outputStream == WLOG_CONSOLE_STDERR) ? stderr : stdout;
+ switch(appender->outputStream)
+ {
+ case WLOG_CONSOLE_STDOUT:
+ fp = stdout;
+ break;
+ case WLOG_CONSOLE_STDERR:
+ fp = stderr;
+ break;
+ default:
+ switch(message->Level)
+ {
+ case WLOG_TRACE:
+ case WLOG_DEBUG:
+ case WLOG_INFO:
+ fp = stdout;
+ break;
+ default:
+ fp = stderr;
+ break;
+ }
+ break;
+ }
- fprintf(fp, "%s%s\n", message->PrefixString, message->TextString);
+ if (message->Level != WLOG_OFF)
+ fprintf(fp, "%s%s\n", message->PrefixString, message->TextString);
#endif
return 1;
}
ConsoleAppender->WritePacketMessage =
(WLOG_APPENDER_WRITE_PACKET_MESSAGE_FN) WLog_ConsoleAppender_WritePacketMessage;
- ConsoleAppender->outputStream = WLOG_CONSOLE_STDOUT;
+ ConsoleAppender->outputStream = WLOG_CONSOLE_DEFAULT;
#ifdef _WIN32
- if (IsDebuggerPresent())
- ConsoleAppender->outputStream = WLOG_CONSOLE_DEBUG;
+ if (IsDebuggerPresent())
+ ConsoleAppender->outputStream = WLOG_CONSOLE_DEBUG;
#endif
return ConsoleAppender;