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

Side by Side Diff: mojo/edk/system/node_controller.cc

Issue 2780433003: Fix leaks in mojo::edk::NodeController (Closed)
Patch Set: . Created 3 years, 8 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "mojo/edk/system/node_controller.h" 5 #include "mojo/edk/system/node_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 base::AutoLock lock(peers_lock_); 703 base::AutoLock lock(peers_lock_);
704 auto& queue = pending_peer_messages_[name]; 704 auto& queue = pending_peer_messages_[name];
705 needs_introduction = queue.empty(); 705 needs_introduction = queue.empty();
706 queue.emplace(std::move(channel_message)); 706 queue.emplace(std::move(channel_message));
707 } 707 }
708 708
709 if (needs_introduction) { 709 if (needs_introduction) {
710 scoped_refptr<NodeChannel> broker = GetBrokerChannel(); 710 scoped_refptr<NodeChannel> broker = GetBrokerChannel();
711 if (!broker) { 711 if (!broker) {
712 DVLOG(1) << "Dropping message for unknown peer: " << name; 712 DVLOG(1) << "Dropping message for unknown peer: " << name;
713
714 base::AutoLock lock(peers_lock_);
715 pending_peer_messages_.erase(name);
713 return; 716 return;
714 } 717 }
715 broker->RequestIntroduction(name); 718 broker->RequestIntroduction(name);
716 } 719 }
717 } 720 }
718 721
719 void NodeController::AcceptIncomingMessages() { 722 void NodeController::AcceptIncomingMessages() {
720 // This is an impactically large value which should never be reached in 723 // This is an impactically large value which should never be reached in
721 // practice. See the CHECK below for usage. 724 // practice. See the CHECK below for usage.
722 constexpr size_t kMaxAcceptedMessages = 1000000; 725 constexpr size_t kMaxAcceptedMessages = 1000000;
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); 931 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
929 932
930 auto it = pending_children_.find(from_node); 933 auto it = pending_children_.find(from_node);
931 if (it == pending_children_.end() || token != from_node) { 934 if (it == pending_children_.end() || token != from_node) {
932 DLOG(ERROR) << "Received unexpected AcceptParent message from " 935 DLOG(ERROR) << "Received unexpected AcceptParent message from "
933 << from_node; 936 << from_node;
934 DropPeer(from_node, nullptr); 937 DropPeer(from_node, nullptr);
935 return; 938 return;
936 } 939 }
937 940
941 {
942 base::AutoLock lock(reserved_ports_lock_);
943 auto it = pending_child_tokens_.find(from_node);
944 if (it != pending_child_tokens_.end()) {
945 std::string token = std::move(it->second);
946 pending_child_tokens_.erase(it);
947 pending_child_tokens_[child_name] = std::move(token);
948 }
949 }
950
938 scoped_refptr<NodeChannel> channel = it->second; 951 scoped_refptr<NodeChannel> channel = it->second;
939 pending_children_.erase(it); 952 pending_children_.erase(it);
940 953
941 DCHECK(channel); 954 DCHECK(channel);
942 955
943 DVLOG(1) << "Parent " << name_ << " accepted child " << child_name; 956 DVLOG(1) << "Parent " << name_ << " accepted child " << child_name;
944 957
945 AddPeer(child_name, channel, false /* start_channel */); 958 AddPeer(child_name, channel, false /* start_channel */);
946 959
947 // TODO(rockot/amistry): We could simplify child initialization if we could 960 // TODO(rockot/amistry): We could simplify child initialization if we could
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
1148 ports::PortRef local_port; 1161 ports::PortRef local_port;
1149 { 1162 {
1150 base::AutoLock lock(reserved_ports_lock_); 1163 base::AutoLock lock(reserved_ports_lock_);
1151 auto it = reserved_ports_.find(token); 1164 auto it = reserved_ports_.find(token);
1152 if (it == reserved_ports_.end()) { 1165 if (it == reserved_ports_.end()) {
1153 DVLOG(1) << "Ignoring request to connect to port for unknown token " 1166 DVLOG(1) << "Ignoring request to connect to port for unknown token "
1154 << token; 1167 << token;
1155 return; 1168 return;
1156 } 1169 }
1157 local_port = it->second.port; 1170 local_port = it->second.port;
1171 reserved_ports_.erase(it);
1158 } 1172 }
1159 1173
1160 int rv = node_->MergePorts(local_port, from_node, connector_port_name); 1174 int rv = node_->MergePorts(local_port, from_node, connector_port_name);
1161 if (rv != ports::OK) 1175 if (rv != ports::OK)
1162 DLOG(ERROR) << "MergePorts failed: " << rv; 1176 DLOG(ERROR) << "MergePorts failed: " << rv;
1163 1177
1164 AcceptIncomingMessages(); 1178 AcceptIncomingMessages();
1165 } 1179 }
1166 1180
1167 void NodeController::OnRequestIntroduction(const ports::NodeName& from_node, 1181 void NodeController::OnRequestIntroduction(const ports::NodeName& from_node,
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
1450 NodeController::PeerConnection::~PeerConnection() = default; 1464 NodeController::PeerConnection::~PeerConnection() = default;
1451 1465
1452 NodeController::PeerConnection& NodeController::PeerConnection:: 1466 NodeController::PeerConnection& NodeController::PeerConnection::
1453 operator=(const PeerConnection& other) = default; 1467 operator=(const PeerConnection& other) = default;
1454 1468
1455 NodeController::PeerConnection& NodeController::PeerConnection:: 1469 NodeController::PeerConnection& NodeController::PeerConnection::
1456 operator=(PeerConnection&& other) = default; 1470 operator=(PeerConnection&& other) = default;
1457 1471
1458 } // namespace edk 1472 } // namespace edk
1459 } // namespace mojo 1473 } // namespace mojo
OLDNEW
« 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