summaryrefslogtreecommitdiffstats
path: root/lldb/source/Core/Log.cpp
diff options
context:
space:
mode:
authorPavel Labath <labath@google.com>2017-02-21 09:58:23 +0000
committerPavel Labath <labath@google.com>2017-02-21 09:58:23 +0000
commitba95a28c18e98c4e9017d9b9a8c36c20eb638d5a (patch)
treeda9ed8e691f5e228791eede9ccfe5e7ca599b5b3 /lldb/source/Core/Log.cpp
parent52a82e2ec6956e84fb52518b4077beb2fadd44b6 (diff)
downloadbcm5719-llvm-ba95a28c18e98c4e9017d9b9a8c36c20eb638d5a.tar.gz
bcm5719-llvm-ba95a28c18e98c4e9017d9b9a8c36c20eb638d5a.zip
Log: Fix race in accessing the stream variable
Summary: The code was attempting to copy the shared pointer member in order to guarantee atomicity, but this is not enough. Instead, protect the pointer with a proper read-write mutex. This bug was present here for a long time, but my recent refactors must have altered the timings slightly, such that now this fails fairly often when running the tests: the test runner runs the "log disable" command just as the thread monitoring the lldb-server child is about to report that the server has exited. I add a test case for this. It's not possible to reproduce the race deterministically in normal circumstances, but I have verified that before the fix, the test failed when run under tsan, and was running fine afterwards. Reviewers: clayborg, zturner Subscribers: lldb-commits Differential Revision: https://reviews.llvm.org/D30168 llvm-svn: 295712
Diffstat (limited to 'lldb/source/Core/Log.cpp')
-rw-r--r--lldb/source/Core/Log.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/lldb/source/Core/Log.cpp b/lldb/source/Core/Log.cpp
index 181dcc25bd7..874b879724d 100644
--- a/lldb/source/Core/Log.cpp
+++ b/lldb/source/Core/Log.cpp
@@ -400,7 +400,7 @@ void Log::WriteHeader(llvm::raw_ostream &OS, llvm::StringRef file,
void Log::WriteMessage(const std::string &message) {
// Make a copy of our stream shared pointer in case someone disables our
// log while we are logging and releases the stream
- auto stream_sp = m_stream_sp;
+ auto stream_sp = GetStream();
if (!stream_sp)
return;
OpenPOWER on IntegriCloud