* in thread function. */
static void *thread_launcher(void *arg)
{
- DWORD res;
+ DWORD res = -1;
void *rc = NULL;
WINPR_THREAD *thread = (WINPR_THREAD *)arg;
exit:
- if (!thread->exited)
- thread->dwExitCode = (DWORD)(size_t)rc;
-
- set_event(thread);
+ if (thread)
+ {
+ if (!thread->exited)
+ thread->dwExitCode = (DWORD)(size_t)rc;
- res = thread->dwExitCode;
- if (thread->detached || !thread->started)
- cleanup_handle(thread);
+ set_event(thread);
+ res = thread->dwExitCode;
+ if (thread->detached || !thread->started)
+ cleanup_handle(thread);
+ }
pthread_exit((void*) (size_t) res);
return rc;
}