diff --git a/lldb/tools/lldb-vscode/FifoFiles.cpp b/lldb/tools/lldb-vscode/FifoFiles.cpp --- a/lldb/tools/lldb-vscode/FifoFiles.cpp +++ b/lldb/tools/lldb-vscode/FifoFiles.cpp @@ -53,37 +53,34 @@ // We use a pointer for this future, because otherwise its normal destructor // would wait for the getline to end, rendering the timeout useless. Optional line; - std::future *future = - new std::future(std::async(std::launch::async, [&]() { - std::ifstream reader(m_fifo_file, std::ifstream::in); - std::string buffer; - std::getline(reader, buffer); - if (!buffer.empty()) - line = buffer; - })); - if (future->wait_for(timeout) == std::future_status::timeout || !line) + std::future future = std::async(std::launch::async, [&]() { + std::ifstream reader(m_fifo_file, std::ifstream::in); + std::string buffer; + std::getline(reader, buffer); + if (!buffer.empty()) + line = buffer; + }); + if (future.wait_for(timeout) == std::future_status::timeout || !line) return createStringError(inconvertibleErrorCode(), "Timed out trying to get messages from the " + m_other_endpoint_name); - delete future; + return json::parse(*line); } Error FifoFileIO::SendJSON(const json::Value &json, std::chrono::milliseconds timeout) { bool done = false; - std::future *future = - new std::future(std::async(std::launch::async, [&]() { - std::ofstream writer(m_fifo_file, std::ofstream::out); - writer << JSONToString(json) << std::endl; - done = true; - })); - if (future->wait_for(timeout) == std::future_status::timeout || !done) { + std::future future = std::async(std::launch::async, [&]() { + std::ofstream writer(m_fifo_file, std::ofstream::out); + writer << JSONToString(json) << std::endl; + done = true; + }); + if (future.wait_for(timeout) == std::future_status::timeout || !done) { return createStringError(inconvertibleErrorCode(), "Timed out trying to send messages to the " + m_other_endpoint_name); } - delete future; return Error::success(); }