From 8d9ccb455ce9cc738d12c99aac4e275fc2b112ee Mon Sep 17 00:00:00 2001 From: "ukai@chromium.org" Date: Tue, 17 Nov 2009 04:12:58 +0000 Subject: Try to fix valgrind error in nss_ocsp.cc I think valgrind error would happen when IO thread was terminated before cert verification timed out. So, observe IO thread destruction and once IO thread destructed, don't post task to cancel the cert verication. BUG=23437 TEST=none Review URL: http://codereview.chromium.org/390011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@32150 0039d316-1c4b-4281-b951-d872f2087c98 --- net/ocsp/nss_ocsp.cc | 47 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 11 deletions(-) (limited to 'net/ocsp') diff --git a/net/ocsp/nss_ocsp.cc b/net/ocsp/nss_ocsp.cc index 62e9c82d..661935f 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() { + virtual ~OCSPInitSingleton() { request_context_ = NULL; } @@ -81,7 +84,8 @@ URLRequestContext* OCSPInitSingleton::request_context_ = NULL; // on IO thread. class OCSPRequestSession : public base::RefCountedThreadSafe, - 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::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; -- cgit v1.1