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

Unified Diff: runtime/bin/socket.cc

Issue 2533303005: VM: Fix memory leak during shutdown (Closed)
Patch Set: Simplify socket.cc by not updating hashmaps during shutdown Created 4 years 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.h ('k') | runtime/platform/hashmap.h » ('j') | 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 d5205723cc8c52d9831b09efafc93658ce30c9ad..cbb9a2c937d895dd251a0f1a85512065539e5565 100644
--- a/runtime/bin/socket.cc
+++ b/runtime/bin/socket.cc
@@ -196,7 +196,8 @@ Dart_Handle ListeningSocketRegistry::CreateBindListen(Dart_Handle socket_object,
}
-bool ListeningSocketRegistry::CloseOneSafe(OSSocket* os_socket) {
+bool ListeningSocketRegistry::CloseOneSafe(OSSocket* os_socket,
+ bool update_hash_maps) {
ASSERT(!mutex_->TryLock());
ASSERT(os_socket != NULL);
ASSERT(os_socket->ref_count > 0);
@@ -204,26 +205,28 @@ bool ListeningSocketRegistry::CloseOneSafe(OSSocket* os_socket) {
if (os_socket->ref_count > 0) {
return false;
}
- // We free the OS socket by removing it from two datastructures.
- RemoveByFd(os_socket->socketfd);
+ if (update_hash_maps) {
+ // We free the OS socket by removing it from two datastructures.
+ RemoveByFd(os_socket->socketfd);
- OSSocket* prev = NULL;
- OSSocket* current = LookupByPort(os_socket->port);
- while (current != os_socket) {
- ASSERT(current != NULL);
- prev = current;
- current = current->next;
- }
+ OSSocket* prev = NULL;
+ OSSocket* current = LookupByPort(os_socket->port);
+ while (current != os_socket) {
+ ASSERT(current != NULL);
+ prev = current;
+ current = current->next;
+ }
- if ((prev == NULL) && (current->next == NULL)) {
- // Remove last element from the list.
- RemoveByPort(os_socket->port);
- } else if (prev == NULL) {
- // Remove first element of the list.
- InsertByPort(os_socket->port, current->next);
- } else {
- // Remove element from the list which is not the first one.
- prev->next = os_socket->next;
+ if ((prev == NULL) && (current->next == NULL)) {
+ // Remove last element from the list.
+ RemoveByPort(os_socket->port);
+ } else if (prev == NULL) {
+ // Remove first element of the list.
+ InsertByPort(os_socket->port, current->next);
+ } else {
+ // Remove element from the list which is not the first one.
+ prev->next = os_socket->next;
+ }
}
ASSERT(os_socket->ref_count == 0);
@@ -234,9 +237,10 @@ bool ListeningSocketRegistry::CloseOneSafe(OSSocket* os_socket) {
void ListeningSocketRegistry::CloseAllSafe() {
MutexLocker ml(mutex_);
- for (HashMap::Entry* p = sockets_by_fd_.Start(); p != NULL;
- p = sockets_by_fd_.Next(p)) {
- CloseOneSafe(reinterpret_cast<OSSocket*>(p->value));
+
+ for (HashMap::Entry* cursor = sockets_by_fd_.Start(); cursor != NULL;
+ cursor = sockets_by_fd_.Next(cursor)) {
+ CloseOneSafe(reinterpret_cast<OSSocket*>(cursor->value), false);
}
}
@@ -245,7 +249,7 @@ bool ListeningSocketRegistry::CloseSafe(intptr_t socketfd) {
ASSERT(!mutex_->TryLock());
OSSocket* os_socket = LookupByFd(socketfd);
if (os_socket != NULL) {
- return CloseOneSafe(os_socket);
+ return CloseOneSafe(os_socket, true);
} else {
// It should be impossible for the event handler to close something that
// hasn't been created before.
« no previous file with comments | « runtime/bin/socket.h ('k') | runtime/platform/hashmap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698