Hi!

apr_thread_join for win32 is implemented incorrectly:
thread handle is destroyed too early (in apr_thread_exit).
If apr_thread_exit() is called before apr_thread_join() and
new object is created (thread handle is reused) before
calling apr_thread_join(), apr_thread_join() will possibly wait
on invalid handle.

Patch is attached.

/fjoe
Index: thread.c
===================================================================
RCS file: /home/cvspublic/apr/threadproc/win32/thread.c,v
retrieving revision 1.57
diff -u -p -r1.57 thread.c
--- thread.c    10 Jun 2004 10:57:25 -0000      1.57
+++ thread.c    31 Jul 2004 21:43:12 -0000
@@ -133,9 +133,6 @@ APR_DECLARE(apr_status_t) apr_thread_exi
     thd->exitval = retval;
     apr_pool_destroy(thd->pool);
 #ifndef _WIN32_WCE
-    if (thd->td) {
-        CloseHandle(thd->td);
-    }
     _endthreadex(0);
 #else
     ExitThread(0);
@@ -149,6 +146,9 @@ APR_DECLARE(apr_status_t) apr_thread_joi
     apr_status_t rv;
 
     rv = WaitForSingleObject(thd->td, INFINITE);
+    if (thd->td) {
+        CloseHandle(thd->td);
+    }
     if ( rv == WAIT_OBJECT_0 || rv == WAIT_ABANDONED) {
         *retval = thd->exitval;
         return APR_SUCCESS;

Reply via email to