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

Unified Diff: net/base/cert_verifier.cc

Issue 5347001: Fix shutdown crash in CertVerifier by using a MessageLoopProxy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address wtc's comments. Whitelist another MessageLoop::current() use. Created 10 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
« base/message_loop_proxy_impl.cc ('K') | « base/message_loop_proxy_impl.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/cert_verifier.cc
diff --git a/net/base/cert_verifier.cc b/net/base/cert_verifier.cc
index 4e941335653adea573ae13ae3dadcb18ebed3c01..2581560a15a293c3c1fc65ab83de41af47af4488 100644
--- a/net/base/cert_verifier.cc
+++ b/net/base/cert_verifier.cc
@@ -8,7 +8,8 @@
#include <private/pprthred.h> // PR_DetatchThread
#endif
-#include "base/message_loop.h"
+#include "base/message_loop_proxy.h"
+#include "base/scoped_ptr.h"
#include "base/worker_pool.h"
#include "net/base/cert_verify_result.h"
#include "net/base/net_errors.h"
@@ -31,7 +32,7 @@ class CertVerifier::Request :
verifier_(verifier),
verify_result_(verify_result),
callback_(callback),
- origin_loop_(MessageLoop::current()),
+ origin_loop_proxy_(base::MessageLoopProxy::CreateForCurrentThread()),
error_(OK) {
}
@@ -49,20 +50,16 @@ class CertVerifier::Request :
PR_DetachThread();
#endif
- Task* reply = NewRunnableMethod(this, &Request::DoCallback);
+ scoped_ptr<Task> reply(NewRunnableMethod(this, &Request::DoCallback));
// The origin loop could go away while we are trying to post to it, so we
// need to call its PostTask method inside a lock. See ~CertVerifier.
- {
- AutoLock locked(origin_loop_lock_);
- if (origin_loop_) {
- origin_loop_->PostTask(FROM_HERE, reply);
- reply = NULL;
- }
+ AutoLock locked(origin_loop_proxy_lock_);
+ if (origin_loop_proxy_) {
+ bool posted = origin_loop_proxy_->PostTask(FROM_HERE, reply.release());
+ // TODO(willchan): Fix leaks and then change this to a DCHECK.
+ LOG_IF(ERROR, !posted) << "Leaked CertVerifier!";
}
-
- // Does nothing if it got posted.
- delete reply;
}
void DoCallback() {
@@ -85,8 +82,8 @@ class CertVerifier::Request :
void Cancel() {
verifier_ = NULL;
- AutoLock locked(origin_loop_lock_);
- origin_loop_ = NULL;
+ AutoLock locked(origin_loop_proxy_lock_);
+ origin_loop_proxy_ = NULL;
}
private:
@@ -106,8 +103,13 @@ class CertVerifier::Request :
CompletionCallback* callback_;
// Used to post ourselves onto the origin thread.
- Lock origin_loop_lock_;
- MessageLoop* origin_loop_;
+ Lock origin_loop_proxy_lock_;
+ // Use a MessageLoopProxy in case the owner of the CertVerifier is leaked, so
+ // this code won't crash: http://crbug.com/42275. If this is leaked, then it
+ // doesn't get Cancel()'d, so |origin_loop_proxy_| doesn't get NULL'd out. If
+ // the MessageLoop goes away, then if we had used a MessageLoop, this would
+ // crash.
+ scoped_refptr<base::MessageLoopProxy> origin_loop_proxy_;
// Assigned on the worker thread, read on the origin thread.
int error_;
« base/message_loop_proxy_impl.cc ('K') | « base/message_loop_proxy_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698