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

Unified Diff: net/base/host_resolver.cc

Issue 19534: Fix HostResolver crash when MessageLoop is destroyed during (Closed)
Patch Set: '' Created 11 years, 10 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/host_resolver.cc
===================================================================
--- net/base/host_resolver.cc (revision 9316)
+++ net/base/host_resolver.cc (working copy)
@@ -63,8 +63,9 @@
//-----------------------------------------------------------------------------
-class HostResolver::Request :
- public base::RefCountedThreadSafe<HostResolver::Request> {
+class HostResolver::Request
+ : public base::RefCountedThreadSafe<HostResolver::Request>,
+ public MessageLoop::DestructionObserver {
public:
Request(HostResolver* resolver,
const std::string& host,
@@ -80,9 +81,10 @@
host_mapper_(host_mapper),
error_(OK),
results_(NULL) {
+ MessageLoop::current()->AddDestructionObserver(this);
}
- ~Request() {
+ virtual ~Request() {
if (results_)
freeaddrinfo(results_);
}
@@ -111,6 +113,12 @@
// Running on the origin thread.
DCHECK(error_ || results_);
+ {
+ AutoLock locked(origin_loop_lock_);
+ if (origin_loop_)
+ origin_loop_->RemoveDestructionObserver(this);
+ }
+
// We may have been cancelled!
if (!resolver_)
return;
@@ -135,6 +143,11 @@
origin_loop_ = NULL;
}
+ virtual void WillDestroyCurrentMessageLoop() {
+ AutoLock locked(origin_loop_lock_);
+ origin_loop_ = NULL;
+ }
+
private:
// Set on the origin thread, read on the worker thread.
std::string host_;
@@ -169,8 +182,10 @@
}
HostResolver::~HostResolver() {
- if (request_)
+ if (request_) {
request_->Cancel();
+ MessageLoop::current()->RemoveDestructionObserver(request_.get());
+ }
}
int HostResolver::Resolve(const std::string& hostname, int port,
@@ -195,6 +210,7 @@
if (!WorkerPool::PostTask(FROM_HERE,
NewRunnableMethod(request_.get(), &Request::DoLookup), true)) {
NOTREACHED();
+ MessageLoop::current()->RemoveDestructionObserver(request_.get());
request_ = NULL;
return ERR_FAILED;
}
« 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