diff --git a/src/common/file_descriptor.cpp b/src/common/file_descriptor.cpp index 24c18f68987223578379983edef198ed5ab171df..6c816ca76445b7701ff4812fe0dded7b80e2ec98 100644 --- a/src/common/file_descriptor.cpp +++ b/src/common/file_descriptor.cpp @@ -222,10 +222,21 @@ int HdcFileDescriptor::LoopReadOnThread() } contextIO->bufIO = buf; contextIO->thisClass = this; + try { + std::thread([contextIO, readMax]() { + HdcFileDescriptor::FileIOOnThread(contextIO, readMax); + }).detach(); + } catch (std::exception &e) { + if (contextIO) { + delete contextIO; + } + if (buf) { + delete[] buf; + } + WRITE_LOG(LOG_FATAL, "std::thread exception %s", e.what()); + return -1; + } ++refIO; - std::thread([contextIO, readMax]() { - HdcFileDescriptor::FileIOOnThread(contextIO, readMax); - }).detach(); return 0; } diff --git a/src/daemon/daemon_unity.cpp b/src/daemon/daemon_unity.cpp index 69161d12663f2264e83bdc63730c65dedbec9557..2cee32d6b2d36b1e59e01cf7308f3c85cd499a5f 100644 --- a/src/daemon/daemon_unity.cpp +++ b/src/daemon/daemon_unity.cpp @@ -111,7 +111,9 @@ int HdcDaemonUnity::ExecuteShell(const string &shellCommand, string optionPath) if (!asyncCommand.Initial(loopTask, funcResultOutput)) { break; } - asyncCommand.ExecuteCommand(shellCommand, optionPath); + if (!asyncCommand.ExecuteCommand(shellCommand, optionPath)) { + break; + } ++refCount; return RET_SUCCESS; } while (false);