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

Unified Diff: blimp/net/tcp_engine_transport.cc

Issue 2511773003: Fix potential teardown race conditions with TCPEngineTransport's PostTasks. (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 | « blimp/net/tcp_engine_transport.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: blimp/net/tcp_engine_transport.cc
diff --git a/blimp/net/tcp_engine_transport.cc b/blimp/net/tcp_engine_transport.cc
index 9d18f1770b6e716af391af87d2d07564b9b11f89..48c2b75852ea307eb29546d16056082cb9f54cb2 100644
--- a/blimp/net/tcp_engine_transport.cc
+++ b/blimp/net/tcp_engine_transport.cc
@@ -22,7 +22,7 @@ namespace blimp {
TCPEngineTransport::TCPEngineTransport(const net::IPEndPoint& address,
net::NetLog* net_log)
- : address_(address), net_log_(net_log) {}
+ : address_(address), net_log_(net_log), weak_factory_(this) {}
TCPEngineTransport::~TCPEngineTransport() {}
@@ -43,20 +43,17 @@ void TCPEngineTransport::Connect(const net::CompletionCallback& callback) {
}
net::CompletionCallback accept_callback = base::Bind(
- &TCPEngineTransport::OnTCPConnectAccepted, base::Unretained(this));
+ &TCPEngineTransport::OnTCPConnectAccepted, weak_factory_.GetWeakPtr());
+ connect_callback_ = callback;
perumaal 2016/11/17 22:44:22 Could you just pass the connect_callback_ as a par
Kevin M 2016/11/17 23:02:49 From the bug: "TCPEngineTransport::Connect() uses
Kevin M 2016/11/17 23:05:41 Sorry, I misread. Yes, I can move the callback as
int result = server_socket_->Accept(&accepted_socket_, accept_callback);
if (result == net::ERR_IO_PENDING) {
- connect_callback_ = callback;
return;
}
- if (result != net::OK) {
- server_socket_.reset();
- }
-
- base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
- base::Bind(callback, result));
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE, base::Bind(&TCPEngineTransport::OnTCPConnectAccepted,
+ weak_factory_.GetWeakPtr(), result));
}
std::unique_ptr<MessagePort> TCPEngineTransport::TakeMessagePort() {
@@ -83,6 +80,7 @@ void TCPEngineTransport::OnTCPConnectAccepted(int result) {
DCHECK_NE(net::ERR_IO_PENDING, result);
DCHECK(accepted_socket_);
if (result != net::OK) {
+ server_socket_.reset();
accepted_socket_.reset();
}
base::ResetAndReturn(&connect_callback_).Run(result);
« no previous file with comments | « blimp/net/tcp_engine_transport.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698