From 49b9e100bfbb3b8da01472a0ff48b2bd92944e01 Mon Sep 17 00:00:00 2001 From: surmeh01 Date: Thu, 17 May 2018 14:11:25 +0100 Subject: Release 18.05 --- RequestThread.cpp | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'RequestThread.cpp') diff --git a/RequestThread.cpp b/RequestThread.cpp index 708a46c8..abaee90c 100644 --- a/RequestThread.cpp +++ b/RequestThread.cpp @@ -26,12 +26,26 @@ RequestThread::RequestThread() RequestThread::~RequestThread() { ALOGV("RequestThread::~RequestThread()"); - // post an EXIT message to the thread - std::shared_ptr nulldata(nullptr); - auto pMsg = std::make_shared(ThreadMsgType::EXIT, nulldata); - PostMsg(pMsg); - // Wait for the thread to terminate, it is deleted automatically - m_Thread->join(); + + try + { + // Coverity fix: The following code may throw an exception of type std::length_error. + + // This code is meant to to terminate the inner thread gracefully by posting an EXIT message + // to the thread's message queue. However, according to Coverity, this code could throw an exception and fail. + // Since only one static instance of RequestThread is used in the driver (in ArmnnPreparedModel), + // this destructor is called only when the application has been closed, which means that + // the inner thread will be terminated anyway, although abruptly, in the event that the destructor code throws. + // Wrapping the destructor's code with a try-catch block simply fixes the Coverity bug. + + // Post an EXIT message to the thread + std::shared_ptr nulldata(nullptr); + auto pMsg = std::make_shared(ThreadMsgType::EXIT, nulldata); + PostMsg(pMsg); + // Wait for the thread to terminate, it is deleted automatically + m_Thread->join(); + } + catch (const std::exception&) { } // Swallow any exception. } void RequestThread::PostMsg(ArmnnPreparedModel* model, -- cgit v1.2.1