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

Unified Diff: runtime/bin/eventhandler_macos.cc

Issue 2760293002: [dart:io] Adds a finalizer to _NativeSocket to avoid socket leaks (Closed)
Patch Set: Address comments Created 3 years, 9 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 | « runtime/bin/eventhandler_linux.cc ('k') | runtime/bin/eventhandler_win.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/eventhandler_macos.cc
diff --git a/runtime/bin/eventhandler_macos.cc b/runtime/bin/eventhandler_macos.cc
index 13423faaca9a8ddc1ec903ca5aedcbd6d86426ca..6e5e89510a194b60076d3852784fe025d9ebee88 100644
--- a/runtime/bin/eventhandler_macos.cc
+++ b/runtime/bin/eventhandler_macos.cc
@@ -222,9 +222,13 @@ void EventHandlerImplementation::HandleInterruptFd() {
shutdown_ = true;
} else {
ASSERT((msg[i].data & COMMAND_MASK) != 0);
-
+ 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.
@@ -252,18 +256,20 @@ 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();
delete di;
+ socket->SetClosedFd();
}
} else {
ASSERT(new_mask == 0);
socket_map_.Remove(GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd));
di->Close();
delete di;
+ socket->SetClosedFd();
}
DartUtils::PostInt32(port, 1 << kDestroyedEvent);
@@ -469,6 +475,7 @@ void EventHandlerImplementation::EventHandlerEntry(uword args) {
handler_impl->HandleEvents(events, result);
}
}
+ DEBUG_ASSERT(ReferenceCounted<Socket>::instances() == 0);
handler->NotifyShutdownDone();
}
« no previous file with comments | « runtime/bin/eventhandler_linux.cc ('k') | runtime/bin/eventhandler_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698