[libcxx] Fix thread join.pass.cpp segfault after r271475

Some pthread implementations do not like being called pthead_join()
with the pthread_t argument set to 0, and causes a segfault. This
patch fixes this issue by validating the pthread_t argument before
invoking pthread_join().

NFC.

Differential revision: http://reviews.llvm.org/D20929

Change-Id: Ief817c57bd0e1f43cbaa03061e02417d6a180c38
Reviewers: EricWF

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@271634 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Asiri Rathnayake
2016-06-03 08:45:26 +00:00
parent 3bf0d98eb1
commit 0dd618b723

View File

@@ -46,14 +46,17 @@ thread::~thread()
void
thread::join()
{
int ec = __libcpp_thread_join(&__t_);
int ec = EINVAL;
if (__t_ != 0)
{
ec = __libcpp_thread_join(&__t_);
if (ec == 0)
__t_ = 0;
}
#ifndef _LIBCPP_NO_EXCEPTIONS
if (ec)
throw system_error(error_code(ec, system_category()), "thread::join failed");
#else
(void)ec;
#endif // _LIBCPP_NO_EXCEPTIONS
__t_ = 0;
}
void