Commit 8c01fe73 authored by Kenton Varda's avatar Kenton Varda

Add missing unref() in the unlikely event that thread creation fails.

parent 562f7eab
...@@ -36,7 +36,10 @@ namespace kj { ...@@ -36,7 +36,10 @@ namespace kj {
Thread::Thread(Function<void()> func): state(new ThreadState { kj::mv(func), nullptr, 2 }) { Thread::Thread(Function<void()> func): state(new ThreadState { kj::mv(func), nullptr, 2 }) {
threadHandle = CreateThread(nullptr, 0, &runThread, state, 0, nullptr); threadHandle = CreateThread(nullptr, 0, &runThread, state, 0, nullptr);
KJ_ASSERT(threadHandle != nullptr, "CreateThread failed."); if (threadHandle == nullptr) {
state->unref();
KJ_FAIL_ASSERT("CreateThread failed.");
}
} }
Thread::~Thread() noexcept(false) { Thread::~Thread() noexcept(false) {
...@@ -78,6 +81,7 @@ Thread::Thread(Function<void()> func): state(new ThreadState { kj::mv(func), nul ...@@ -78,6 +81,7 @@ Thread::Thread(Function<void()> func): state(new ThreadState { kj::mv(func), nul
int pthreadResult = pthread_create(reinterpret_cast<pthread_t*>(&threadId), int pthreadResult = pthread_create(reinterpret_cast<pthread_t*>(&threadId),
nullptr, &runThread, state); nullptr, &runThread, state);
if (pthreadResult != 0) { if (pthreadResult != 0) {
state->unref();
KJ_FAIL_SYSCALL("pthread_create", pthreadResult); KJ_FAIL_SYSCALL("pthread_create", pthreadResult);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment