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

Unified Diff: net/ocsp/nss_ocsp.cc

Issue 390011: Try to fix valgrind error in nss_ocsp.cc (Closed)
Patch Set: fix wtc's comment Created 11 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/ocsp/nss_ocsp.cc
diff --git a/net/ocsp/nss_ocsp.cc b/net/ocsp/nss_ocsp.cc
index ce9fc1a44995425c264a36bebc4fa2672b2df8b1..eaf6aaba82a6a4dc7087f88b4e988d3fe780281d 100644
--- a/net/ocsp/nss_ocsp.cc
+++ b/net/ocsp/nss_ocsp.cc
@@ -38,10 +38,13 @@ static const int kRecvBufferSize = 4096;
// CertVerifier's thread (i.e. worker pool, not on the I/O thread).
// It supports blocking mode only.
-class OCSPInitSingleton {
+class OCSPInitSingleton : public MessageLoop::DestructionObserver {
public:
+ virtual void WillDestroyCurrentMessageLoop() {
+ io_loop_ = NULL;
+ };
+
MessageLoop* io_thread() const {
- DCHECK(io_loop_);
return io_loop_;
}
@@ -57,7 +60,7 @@ class OCSPInitSingleton {
private:
friend struct DefaultSingletonTraits<OCSPInitSingleton>;
OCSPInitSingleton();
- ~OCSPInitSingleton() {
+ virtual ~OCSPInitSingleton() {
request_context_ = NULL;
}
@@ -81,7 +84,8 @@ scoped_refptr<URLRequestContext> OCSPInitSingleton::request_context_;
// on IO thread.
class OCSPRequestSession
: public base::RefCountedThreadSafe<OCSPRequestSession>,
- public URLRequest::Delegate {
+ public URLRequest::Delegate,
+ public MessageLoop::DestructionObserver {
public:
OCSPRequestSession(const GURL& url,
const char* http_request_method,
@@ -110,10 +114,11 @@ class OCSPRequestSession
}
void Start() {
- DCHECK(io_loop_);
- io_loop_->PostTask(
- FROM_HERE,
- NewRunnableMethod(this, &OCSPRequestSession::StartURLRequest));
+ if (io_loop_) {
+ io_loop_->PostTask(
+ FROM_HERE,
+ NewRunnableMethod(this, &OCSPRequestSession::StartURLRequest));
+ }
}
bool Started() const {
@@ -121,9 +126,11 @@ class OCSPRequestSession
}
void Cancel() {
- io_loop_->PostTask(
- FROM_HERE,
- NewRunnableMethod(this, &OCSPRequestSession::CancelURLRequest));
+ if (io_loop_) {
+ io_loop_->PostTask(
+ FROM_HERE,
+ NewRunnableMethod(this, &OCSPRequestSession::CancelURLRequest));
+ }
}
bool Finished() const {
@@ -214,7 +221,19 @@ class OCSPRequestSession
cv_.Signal();
delete request_;
request_ = NULL;
+ io_loop_->RemoveDestructionObserver(this);
+ io_loop_ = NULL;
+ }
+ }
+
+ virtual void WillDestroyCurrentMessageLoop() {
+ DCHECK(MessageLoopForIO::current() == io_loop_);
+ if (request_) {
+ request_->Cancel();
+ delete request_;
+ request_ = NULL;
}
+ io_loop_ = NULL;
}
private:
@@ -222,12 +241,17 @@ class OCSPRequestSession
virtual ~OCSPRequestSession() {
DCHECK(!request_);
+ if (io_loop_)
+ io_loop_->RemoveDestructionObserver(this);
+ io_loop_ = NULL;
}
void StartURLRequest() {
DCHECK(MessageLoopForIO::current() == io_loop_);
DCHECK(!request_);
+ io_loop_->AddDestructionObserver(this);
+
request_ = new URLRequest(url_, this);
request_->set_context(
Singleton<OCSPInitSingleton>::get()->url_request_context());
@@ -500,6 +524,7 @@ SECStatus OCSPFree(SEC_HTTP_REQUEST_SESSION request) {
OCSPInitSingleton::OCSPInitSingleton()
: io_loop_(MessageLoopForIO::current()) {
+ io_loop_->AddDestructionObserver(this);
client_fcn_.version = 1;
SEC_HttpClientFcnV1Struct *ft = &client_fcn_.fcnTable.ftable1;
ft->createSessionFcn = OCSPCreateSession;
« 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