diff --git a/ipc/chromium/src/base/message_pump_libevent.cc b/ipc/chromium/src/base/message_pump_libevent.cc index bc0a6f054e4a..c309234ded42 100644 --- a/ipc/chromium/src/base/message_pump_libevent.cc +++ b/ipc/chromium/src/base/message_pump_libevent.cc @@ -175,6 +175,23 @@ bool MessagePumpLibevent::WatchFileDescriptor(int fd, should_delete_event = false; // Ownership is transferred to the controller. evt = mozilla::MakeUnique(); + } else { + // It's illegal to use this function to listen on 2 separate fds with the + // same |controller|. + if (EVENT_FD(evt.get()) != fd) { + NOTREACHED() << "FDs don't match" << EVENT_FD(evt.get()) << "!=" << fd; + return false; + } + + // Make sure we don't pick up any funky internal libevent masks. + int old_interest_mask = evt.get()->ev_events & + (EV_READ | EV_WRITE | EV_PERSIST); + + // Combine old/new event masks. + event_mask |= old_interest_mask; + + // Must disarm the event before we can reuse it. + event_del(evt.get()); } // Set current interest mask and message pump for this event. diff --git a/ipc/chromium/src/chrome/common/ipc_channel_posix.cc b/ipc/chromium/src/chrome/common/ipc_channel_posix.cc index 3fcabc50b281..0e77aff72277 100644 --- a/ipc/chromium/src/chrome/common/ipc_channel_posix.cc +++ b/ipc/chromium/src/chrome/common/ipc_channel_posix.cc @@ -844,6 +844,8 @@ void Channel::ChannelImpl::OnFileCanReadWithoutBlocking(int fd) { if (!ProcessIncomingMessages()) { Close(); listener_->OnChannelError(); + // The OnChannelError() call may delete this, so we need to exit now. + return; } }