Fixed NULL pointer dereference.
authorArmin Novak <armin.novak@gmail.com>
Sun, 16 Nov 2014 15:51:04 +0000 (16:51 +0100)
committerArmin Novak <armin.novak@gmail.com>
Sun, 16 Nov 2014 15:51:04 +0000 (16:51 +0100)
winpr/libwinpr/thread/thread.c

index 8916f22..aeae97a 100644 (file)
@@ -236,7 +236,7 @@ static int thread_compare(void *a, void *b)
  * in thread function. */
 static void *thread_launcher(void *arg)
 {
-       DWORD res;
+       DWORD res = -1;
        void *rc = NULL;
        WINPR_THREAD *thread = (WINPR_THREAD *)arg;
 
@@ -260,15 +260,17 @@ static void *thread_launcher(void *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;
 }