Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(575)

Unified Diff: mojo/edk/system/message_pipe_dispatcher.cc

Issue 1589693002: Avoid shutdown leak. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | mojo/edk/system/raw_channel.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/edk/system/message_pipe_dispatcher.cc
diff --git a/mojo/edk/system/message_pipe_dispatcher.cc b/mojo/edk/system/message_pipe_dispatcher.cc
index a4bbaafc8642351073e625c3424268e2fac27218..7e69b7343b798611d14edb34dde9f7bdd4d21b84 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() {
« no previous file with comments | « no previous file | mojo/edk/system/raw_channel.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698