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() { |