summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYann Ylavic <ylavic@apache.org>2022-01-19 12:00:38 +0000
committerYann Ylavic <ylavic@apache.org>2022-01-19 12:00:38 +0000
commit9f9375278461a2c7675d66411412af65b08c0e6c (patch)
treea35cd28a6092731b639177a68f31faa9446a97ae
parentea8d9ad623550b3ca466e272c8738002d2e0b088 (diff)
downloadapr-9f9375278461a2c7675d66411412af65b08c0e6c.tar.gz
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. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1897198 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--threadproc/beos/thread.c20
-rw-r--r--threadproc/unix/thread.c14
-rw-r--r--threadproc/win32/thread.c1
3 files changed, 15 insertions, 20 deletions
diff --git a/threadproc/beos/thread.c b/threadproc/beos/thread.c
index 8dd95ea8b..988f8f4ff 100644
--- a/threadproc/beos/thread.c
+++ b/threadproc/beos/thread.c
@@ -161,21 +161,19 @@ APR_DECLARE(apr_status_t) apr_thread_join(apr_status_t *retval, apr_thread_t *th
}
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)
diff --git a/threadproc/unix/thread.c b/threadproc/unix/thread.c
index 3b6ef2809..d1ae872c6 100644
--- a/threadproc/unix/thread.c
+++ b/threadproc/unix/thread.c
@@ -235,24 +235,22 @@ APR_DECLARE(apr_status_t) apr_thread_join(apr_status_t *retval,
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)
diff --git a/threadproc/win32/thread.c b/threadproc/win32/thread.c
index 02956c59f..569268cd1 100644
--- a/threadproc/win32/thread.c
+++ b/threadproc/win32/thread.c
@@ -181,7 +181,6 @@ APR_DECLARE(apr_status_t) apr_thread_join(apr_status_t *retval,
if (rv == APR_SUCCESS) {
CloseHandle(thd->td);
apr_pool_destroy(thd->pool);
- thd->td = NULL;
}
return rv;