summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjam <jam@chromium.org>2016-01-13 21:08:45 -0800
committerCommit bot <commit-bot@chromium.org>2016-01-14 05:09:32 +0000
commitd8a022e9822b5b7734b0f7389480cdcdb65c9cb2 (patch)
tree2c7914aa560ba49d70820aba1090907cc64ffb28
parent10ada8c226b7b569c3b20b8d594fb0fbcae2b995 (diff)
downloadchromium_src-d8a022e9822b5b7734b0f7389480cdcdb65c9cb2.zip
chromium_src-d8a022e9822b5b7734b0f7389480cdcdb65c9cb2.tar.gz
chromium_src-d8a022e9822b5b7734b0f7389480cdcdb65c9cb2.tar.bz2
Avoid shutdown leak in RawChannel and MessgePipeDispatcher.
This is to keep LSAN bots happy. BUG=561803,574325 TBR=ben Review URL: https://codereview.chromium.org/1589693002 Cr-Commit-Position: refs/heads/master@{#369332}
-rw-r--r--mojo/edk/system/message_pipe_dispatcher.cc11
-rw-r--r--mojo/edk/system/raw_channel.cc9
2 files changed, 16 insertions, 4 deletions
diff --git a/mojo/edk/system/message_pipe_dispatcher.cc b/mojo/edk/system/message_pipe_dispatcher.cc
index a4bbaaf..7e69b73 100644
--- a/mojo/edk/system/message_pipe_dispatcher.cc
+++ b/mojo/edk/system/message_pipe_dispatcher.cc
@@ -470,8 +470,15 @@ void MessagePipeDispatcher::CloseImplNoLock() {
// destruction). So to avoid UAF, manually add a reference and only release it
// if the task runs.
AddRef();
- internal::g_io_thread_task_runner->PostTask(
- FROM_HERE, base::Bind(&MessagePipeDispatcher::CloseOnIOAndRelease, this));
+ if (!internal::g_io_thread_task_runner->PostTask(
+ FROM_HERE,
+ base::Bind(&MessagePipeDispatcher::CloseOnIOAndRelease, this))) {
+ // Avoid a shutdown leak in unittests. If the thread is shutting down,
+ // we can't connect to the other end to let it know that we're closed either
+ // way.
+ if (!transferable_ && non_transferable_state_ == WAITING_FOR_READ_OR_WRITE)
+ Release();
+ }
}
void MessagePipeDispatcher::SerializeInternal() {
diff --git a/mojo/edk/system/raw_channel.cc b/mojo/edk/system/raw_channel.cc
index 5d0a04c..93c2d05 100644
--- a/mojo/edk/system/raw_channel.cc
+++ b/mojo/edk/system/raw_channel.cc
@@ -726,8 +726,13 @@ void RawChannel::CallOnReadCompleted(IOResult io_result, size_t bytes_read) {
}
void RawChannel::WillDestroyCurrentMessageLoop() {
- base::AutoLock locker(read_lock_);
- OnReadCompletedNoLock(IO_FAILED_SHUTDOWN, 0);
+ {
+ base::AutoLock locker(read_lock_);
+ OnReadCompletedNoLock(IO_FAILED_SHUTDOWN, 0);
+ }
+ // The PostTask inside Shutdown() will never be called, so manually call it
+ // here to avoid leaks in LSAN builds.
+ Shutdown();
}
} // namespace edk