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

Unified Diff: runtime/bin/socket.cc

Issue 2229973002: Revert: Fixes memory leaks in the eventhandler (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 4 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.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 f7bc5822d3c3924cfd4463cc7c3e3a495da64a2f..745306d0e53aef80dffdde95f79f249bda1bfe4d 100644
--- a/runtime/bin/socket.cc
+++ b/runtime/bin/socket.cc
@@ -127,57 +127,42 @@ Dart_Handle ListeningSocketRegistry::CreateBindListen(Dart_Handle socket_object,
}
-bool ListeningSocketRegistry::CloseOneSafe(OSSocket* os_socket) {
+bool ListeningSocketRegistry::CloseSafe(intptr_t socketfd) {
ASSERT(!mutex_->TryLock());
- ASSERT(os_socket != NULL);
- ASSERT(os_socket->ref_count > 0);
- os_socket->ref_count--;
- if (os_socket->ref_count > 0) {
- return false;
- }
- // We free the OS socket by removing it from two datastructures.
- sockets_by_fd_.erase(os_socket->socketfd);
-
- OSSocket *prev = NULL;
- OSSocket *current = sockets_by_port_[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.
- sockets_by_port_.erase(os_socket->port);
- } else if (prev == NULL) {
- // Remove first element of the list.
- sockets_by_port_[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);
- delete os_socket;
- return true;
-}
+ SocketsIterator it = sockets_by_fd_.find(socketfd);
+ if (it != sockets_by_fd_.end()) {
+ OSSocket *os_socket = it->second;
-void ListeningSocketRegistry::CloseAllSafe() {
- MutexLocker ml(mutex_);
- SocketsIterator it = sockets_by_fd_.begin();
- while (it != sockets_by_fd_.end()) {
- CloseOneSafe(it->second);
- it++;
- }
-}
+ ASSERT(os_socket->ref_count > 0);
+ os_socket->ref_count--;
+ if (os_socket->ref_count == 0) {
+ // We free the OS socket by removing it from two datastructures.
+ sockets_by_fd_.erase(socketfd);
+
+ OSSocket *prev = NULL;
+ OSSocket *current = sockets_by_port_[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.
+ sockets_by_port_.erase(os_socket->port);
+ } else if (prev == NULL) {
+ // Remove first element of the list.
+ sockets_by_port_[os_socket->port] = current->next;
+ } else {
+ // Remove element from the list which is not the first one.
+ prev->next = os_socket->next;
+ }
-bool ListeningSocketRegistry::CloseSafe(intptr_t socketfd) {
- ASSERT(!mutex_->TryLock());
- SocketsIterator it = sockets_by_fd_.find(socketfd);
- if (it != sockets_by_fd_.end()) {
- return CloseOneSafe(it->second);
+ delete os_socket;
+ return true;
+ }
+ return false;
} 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