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

Unified Diff: runtime/bin/socket_win.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/socket_macos.cc ('k') | tests/standalone/io/socket_bind_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/socket_win.cc
diff --git a/runtime/bin/socket_win.cc b/runtime/bin/socket_win.cc
index dbb3d62ebe3ce71b790c579ce04fec557938181d..a7061f70ff900e6fcaa190c60bb8e50e25cb5061 100644
--- a/runtime/bin/socket_win.cc
+++ b/runtime/bin/socket_win.cc
@@ -46,6 +46,22 @@ bool Socket::FormatNumericAddress(const RawAddr& addr, char* address, int len) {
}
+Socket::Socket(intptr_t fd) : ReferenceCounted(), fd_(fd), port_(ILLEGAL_PORT) {
+ ASSERT(fd_ != kClosedFd);
+ Handle* handle = reinterpret_cast<Handle*>(fd_);
+ ASSERT(handle != NULL);
+}
+
+
+void Socket::SetClosedFd() {
+ ASSERT(fd_ != kClosedFd);
+ Handle* handle = reinterpret_cast<Handle*>(fd_);
+ ASSERT(handle != NULL);
+ handle->Release();
+ fd_ = kClosedFd;
+}
+
+
static Mutex* init_mutex = new Mutex();
static bool socket_initialized = false;
@@ -165,7 +181,7 @@ static intptr_t Connect(intptr_t fd,
if (status != NO_ERROR) {
int rc = WSAGetLastError();
handle->mark_closed(); // Destructor asserts that socket is marked closed.
- delete handle;
+ handle->Release();
closesocket(s);
SetLastError(rc);
return -1;
@@ -196,11 +212,12 @@ static intptr_t Connect(intptr_t fd,
rc = WSAGetLastError();
// Cleanup in case of error.
OverlappedBuffer::DisposeBuffer(overlapped);
+ handle->Release();
} else {
rc = WSAGetLastError();
}
handle->Close();
- delete handle;
+ handle->Release();
SetLastError(rc);
return -1;
}
@@ -497,7 +514,7 @@ intptr_t ServerSocket::CreateBindListen(const RawAddr& addr,
intptr_t new_s = CreateBindListen(addr, backlog, v6_only);
DWORD rc = WSAGetLastError();
closesocket(s);
- delete listen_socket;
+ listen_socket->Release();
SetLastError(rc);
return new_s;
}
@@ -506,7 +523,7 @@ intptr_t ServerSocket::CreateBindListen(const RawAddr& addr,
if (status == SOCKET_ERROR) {
DWORD rc = WSAGetLastError();
closesocket(s);
- delete listen_socket;
+ listen_socket->Release();
SetLastError(rc);
return -1;
}
@@ -526,7 +543,7 @@ bool ServerSocket::StartAccept(intptr_t fd) {
if (!listen_socket->HasPendingAccept()) {
// Delete socket now, if there are no pending accepts. Otherwise,
// the event-handler will take care of deleting it.
- delete listen_socket;
+ listen_socket->Release();
}
SetLastError(rc);
return false;
« no previous file with comments | « runtime/bin/socket_macos.cc ('k') | tests/standalone/io/socket_bind_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698