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

Unified Diff: runtime/bin/socket.cc

Issue 2540013002: VM: Fix segfault during shutdown of socket listening registry (Closed)
Patch Set: Created 4 years, 1 month 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/socket.cc
diff --git a/runtime/bin/socket.cc b/runtime/bin/socket.cc
index b0e384c8b18487f67f2b0664b0f63c785e6d1306..f7aa6d08718edfba28e5f6dd5b66b07e926603a0 100644
--- a/runtime/bin/socket.cc
+++ b/runtime/bin/socket.cc
@@ -103,42 +103,46 @@ Dart_Handle ListeningSocketRegistry::CreateBindListen(Dart_Handle socket_object,
bool shared) {
MutexLocker ml(ListeningSocketRegistry::mutex_);
Florian Schneider 2016/11/30 00:21:01 nit: no need to use qualified name here MutexLock
kustermann 2016/11/30 10:51:10 Done.
+ OSSocket* first_os_socket = NULL;
intptr_t port = SocketAddress::GetAddrPort(addr);
- OSSocket* first_os_socket = LookupByPort(port);
- if (first_os_socket != NULL) {
- // There is already a socket listening on this port. We need to ensure
- // that if there is one also listening on the same address, it was created
- // with `shared = true`, ...
- OSSocket* os_socket = first_os_socket;
- OSSocket* os_socket_same_addr = findOSSocketWithAddress(os_socket, addr);
-
- if (os_socket_same_addr != NULL) {
- if (!os_socket_same_addr->shared || !shared) {
- OSError os_error(-1,
- "The shared flag to bind() needs to be `true` if "
- "binding multiple times on the same (address, port) "
- "combination.",
- OSError::kUnknown);
- return DartUtils::NewDartOSError(&os_error);
- }
- if (os_socket_same_addr->v6_only != v6_only) {
- OSError os_error(-1,
- "The v6Only flag to bind() needs to be the same if "
- "binding multiple times on the same (address, port) "
- "combination.",
- OSError::kUnknown);
- return DartUtils::NewDartOSError(&os_error);
+ if (port > 0) {
+ first_os_socket = LookupByPort(port);
+ if (first_os_socket != NULL) {
+ // There is already a socket listening on this port. We need to ensure
+ // that if there is one also listening on the same address, it was created
+ // with `shared = true`, ...
+ OSSocket* os_socket = first_os_socket;
+ OSSocket* os_socket_same_addr = findOSSocketWithAddress(os_socket, addr);
+
+ if (os_socket_same_addr != NULL) {
+ if (!os_socket_same_addr->shared || !shared) {
+ OSError os_error(-1,
+ "The shared flag to bind() needs to be `true` if "
+ "binding multiple times on the same (address, port) "
+ "combination.",
+ OSError::kUnknown);
+ return DartUtils::NewDartOSError(&os_error);
+ }
+ if (os_socket_same_addr->v6_only != v6_only) {
+ OSError os_error(-1,
+ "The v6Only flag to bind() needs to be the same if "
+ "binding multiple times on the same (address, port) "
+ "combination.",
+ OSError::kUnknown);
+ return DartUtils::NewDartOSError(&os_error);
+ }
+
+ // This socket creation is the exact same as the one which originally
+ // created the socket. We therefore increment the refcount and reuse
+ // the file descriptor.
+ os_socket->ref_count++;
+
+ // We set as a side-effect the file descriptor on the dart
+ // socket_object.
+ Socket::SetSocketIdNativeField(socket_object, os_socket->socketfd);
+
+ return Dart_True();
}
-
- // This socket creation is the exact same as the one which originally
- // created the socket. We therefore increment the refcount and reuse
- // the file descriptor.
- os_socket->ref_count++;
-
- // We set as a side-effect the file descriptor on the dart socket_object.
- Socket::SetSocketIdNativeField(socket_object, os_socket->socketfd);
-
- return Dart_True();
}
}
@@ -159,6 +163,11 @@ Dart_Handle ListeningSocketRegistry::CreateBindListen(Dart_Handle socket_object,
intptr_t allocated_port = Socket::GetPort(socketfd);
ASSERT(allocated_port > 0);
+ if (allocated_port != port) {
+ ASSERT(port == 0);
Florian Schneider 2016/11/30 00:21:01 Maybe add a short comment here about the scenario
kustermann 2016/11/30 10:51:10 Done.
+ first_os_socket = LookupByPort(allocated_port);
+ }
+
OSSocket* os_socket =
new OSSocket(addr, allocated_port, v6_only, shared, socketfd);
os_socket->ref_count = 1;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698