From 32dd7ad7926f9f4ce7e38bef30d5e7aeb7507cc2 Mon Sep 17 00:00:00 2001 From: Krzysztof Jackiewicz Date: Tue, 2 Jul 2024 14:59:59 +0200 Subject: [PATCH] Ensure async thread join ConnectionThread destructor calls EventFd::notify() which may throw. In such case the thread will be destroyed before joining, which will result in program termination. Make sure that the std::thread::join() is called even if EventFd::notify throws. Change-Id: Ieb5cbcf4440b2c9d22c2d30410fd2b9263070b2f --- src/manager/client-async/connection-thread.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/manager/client-async/connection-thread.cpp b/src/manager/client-async/connection-thread.cpp index 1de71de..6761020 100644 --- a/src/manager/client-async/connection-thread.cpp +++ b/src/manager/client-async/connection-thread.cpp @@ -73,14 +73,19 @@ ConnectionThread::~ConnectionThread() m_join = true; try { m_eventFd.notify(); - m_thread.join(); - } catch (CKM::Exception &e) { + } catch (const CKM::Exception &e) { LogError("CKM::Exception::Exception " << e.DumpToString()); - } catch (std::exception &e) { + } catch (const std::exception &e) { LogError("STD exception " << e.what()); } catch (...) { LogError("Unknown exception occured"); } + + try { + m_thread.join(); + } catch (const std::system_error &e) { + LogError("STD exception " << e.what()); + } } void ConnectionThread::run() -- 2.7.4