Index: runtime/bin/eventhandler_fuchsia.cc |
diff --git a/runtime/bin/eventhandler_fuchsia.cc b/runtime/bin/eventhandler_fuchsia.cc |
index 438d36eb1efa60c90873dcfeda05807a3b4756d9..3d586ca034995a3f1ce01d1943768d7253d5d24b 100644 |
--- a/runtime/bin/eventhandler_fuchsia.cc |
+++ b/runtime/bin/eventhandler_fuchsia.cc |
@@ -279,8 +279,13 @@ void EventHandlerImplementation::HandleInterruptFd() { |
} else { |
ASSERT((msg[i].data & COMMAND_MASK) != 0); |
LOG_INFO("HandleInterruptFd command\n"); |
+ Socket* socket = reinterpret_cast<Socket*>(msg[i].id); |
+ RefCntReleaseScope<Socket> rs(socket); |
+ if (socket->fd() == -1) { |
+ continue; |
+ } |
DescriptorInfo* di = |
- GetDescriptorInfo(msg[i].id, IS_LISTENING_SOCKET(msg[i].data)); |
+ GetDescriptorInfo(socket->fd(), IS_LISTENING_SOCKET(msg[i].data)); |
if (IS_COMMAND(msg[i].data, kShutdownReadCommand)) { |
ASSERT(!di->IsListeningSocket()); |
// Close the socket for reading. |
@@ -311,13 +316,14 @@ void EventHandlerImplementation::HandleInterruptFd() { |
MutexLocker locker(registry->mutex()); |
- if (registry->CloseSafe(fd)) { |
+ if (registry->CloseSafe(socket)) { |
ASSERT(new_mask == 0); |
socket_map_.Remove(GetHashmapKeyFromFd(fd), |
GetHashmapHashFromFd(fd)); |
di->Close(); |
LOG_INFO("Closed %d\n", di->fd()); |
delete di; |
+ socket->SetClosedFd(); |
} |
} else { |
ASSERT(new_mask == 0); |
@@ -325,6 +331,7 @@ void EventHandlerImplementation::HandleInterruptFd() { |
di->Close(); |
LOG_INFO("Closed %d\n", di->fd()); |
delete di; |
+ socket->SetClosedFd(); |
} |
bool success = DartUtils::PostInt32(port, 1 << kDestroyedEvent); |
@@ -468,6 +475,7 @@ void EventHandlerImplementation::Poll(uword args) { |
handler_impl->HandleEvents(events, result); |
} |
} |
+ DEBUG_ASSERT(ReferenceCounted<Socket>::instances() == 0); |
handler->NotifyShutdownDone(); |
} |