You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by yl...@apache.org on 2022/01/19 12:00:38 UTC

svn commit: r1897198 - in /apr/apr/trunk/threadproc: beos/thread.c unix/thread.c win32/thread.c

Author: ylavic
Date: Wed Jan 19 12:00:38 2022
New Revision: 1897198

URL: http://svn.apache.org/viewvc?rev=1897198&view=rev
Log:
apr_thread: Follow up to r1897197: Safer apr_thread_join().

Make sure apr_thread_join() behaves correctly w.r.t. the returned value
and pool destroy for all archs.


Modified:
    apr/apr/trunk/threadproc/beos/thread.c
    apr/apr/trunk/threadproc/unix/thread.c
    apr/apr/trunk/threadproc/win32/thread.c

Modified: apr/apr/trunk/threadproc/beos/thread.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/threadproc/beos/thread.c?rev=1897198&r1=1897197&r2=1897198&view=diff
==============================================================================
--- apr/apr/trunk/threadproc/beos/thread.c (original)
+++ apr/apr/trunk/threadproc/beos/thread.c Wed Jan 19 12:00:38 2022
@@ -161,21 +161,19 @@ APR_DECLARE(apr_status_t) apr_thread_joi
     }
 
     ret = wait_for_thread(thd->td, &rv);
-    if (ret == B_NO_ERROR) {
-        *retval = rv;
-        return APR_SUCCESS;
-    }
-    else {
+    if (ret != B_NO_ERROR) {
         /* if we've missed the thread's death, did we set an exit value prior
          * to it's demise?  If we did return that.
          */
-        if (thd->exitval != -1) {
-            *retval = thd->exitval;
-            apr_pool_destroy(thd->pool);
-            return APR_SUCCESS;
-        } else 
-            return ret;
+        if (thd->exitval == -1) {
+            return errno;
+        }
+        rv = thd->exitval;
     }
+
+    *retval = rv;
+    apr_pool_destroy(thd->pool);
+    return APR_SUCCESS;
 }
 
 APR_DECLARE(apr_status_t) apr_thread_detach(apr_thread_t *thd)

Modified: apr/apr/trunk/threadproc/unix/thread.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/threadproc/unix/thread.c?rev=1897198&r1=1897197&r2=1897198&view=diff
==============================================================================
--- apr/apr/trunk/threadproc/unix/thread.c (original)
+++ apr/apr/trunk/threadproc/unix/thread.c Wed Jan 19 12:00:38 2022
@@ -235,24 +235,22 @@ APR_DECLARE(apr_status_t) apr_thread_joi
                                           apr_thread_t *thd)
 {
     apr_status_t stat;
-    apr_status_t *thread_stat;
+    void *thread_stat;
 
     if (thd->detached) {
         return APR_EINVAL;
     }
 
-    if ((stat = pthread_join(*thd->td,(void *)&thread_stat)) == 0) {
-        *retval = thd->exitval;
-        apr_pool_destroy(thd->pool);
-        return APR_SUCCESS;
-    }
-    else {
+    if ((stat = pthread_join(*thd->td, &thread_stat))) {
 #ifdef HAVE_ZOS_PTHREADS
         stat = errno;
 #endif
-
         return stat;
     }
+
+    *retval = thd->exitval;
+    apr_pool_destroy(thd->pool);
+    return APR_SUCCESS;
 }
 
 APR_DECLARE(apr_status_t) apr_thread_detach(apr_thread_t *thd)

Modified: apr/apr/trunk/threadproc/win32/thread.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/threadproc/win32/thread.c?rev=1897198&r1=1897197&r2=1897198&view=diff
==============================================================================
--- apr/apr/trunk/threadproc/win32/thread.c (original)
+++ apr/apr/trunk/threadproc/win32/thread.c Wed Jan 19 12:00:38 2022
@@ -181,7 +181,6 @@ APR_DECLARE(apr_status_t) apr_thread_joi
     if (rv == APR_SUCCESS) {
         CloseHandle(thd->td);
         apr_pool_destroy(thd->pool);
-        thd->td = NULL;
     }
 
     return rv;