Ensure async thread join 50/313850/3 tizen
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Tue, 2 Jul 2024 12:59:59 +0000 (14:59 +0200)
committerDariusz Michaluk <d.michaluk@samsung.com>
Wed, 3 Jul 2024 09:59:50 +0000 (09:59 +0000)
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

index 1de71de..6761020 100644 (file)
@@ -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()