Hi,

I have a problem about handle leak related to threads on Windows2000/XP.

Excerpt from MSVC help;
"Like the Win32 ExitThread API, _endthreadex does not close the thread handle.
Therefore, when you use _beginthreadex and _endthreadex,
you must close the thread handle by calling the Win32 CloseHandle API."

SUZUKI Rintaro <[EMAIL PROTECTED]> wrote the patch.
Please review the attachment file.

Thanks.
- INOUE Seiichiro <[EMAIL PROTECTED]>
Index: thread.c
===================================================================
RCS file: /home/cvspublic/apr/threadproc/win32/thread.c,v
retrieving revision 1.47
diff -u -r1.47 thread.c
--- thread.c    19 Mar 2002 17:54:00 -0000      1.47
+++ thread.c    22 Aug 2002 12:56:58 -0000
@@ -138,6 +138,7 @@
 #endif
     if (attr && attr->detach) {
         CloseHandle((*new)->td);
+       (*new)->td = NULL;
     }
 
     return APR_SUCCESS;
@@ -149,6 +150,9 @@
     thd->exitval = retval;
     apr_pool_destroy(thd->pool);
 #ifndef _WIN32_WCE
+    if (thd->td) {
+       CloseHandle(thd->td);
+    }
     _endthreadex(0);
 #else
     ExitThread(0);
@@ -172,7 +176,8 @@
 
 APR_DECLARE(apr_status_t) apr_thread_detach(apr_thread_t *thd)
 {
-    if (CloseHandle(thd->td)) {
+    if (thd->td && CloseHandle(thd->td)) {
+       thd->td = NULL;
         return APR_SUCCESS;
     }
     else {

Reply via email to