summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorukai@chromium.org <ukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-17 04:12:58 +0000
committerukai@chromium.org <ukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-17 04:12:58 +0000
commit8d9ccb455ce9cc738d12c99aac4e275fc2b112ee (patch)
treea7aad11302c492037671dd64e9d4b05b520c4fd5
parent7a2851790d629f59326575ab8bbe8ddc26e7ced3 (diff)
downloadchromium_src-8d9ccb455ce9cc738d12c99aac4e275fc2b112ee.zip
chromium_src-8d9ccb455ce9cc738d12c99aac4e275fc2b112ee.tar.gz
chromium_src-8d9ccb455ce9cc738d12c99aac4e275fc2b112ee.tar.bz2
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
-rw-r--r--net/ocsp/nss_ocsp.cc47
1 files changed, 36 insertions, 11 deletions
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();
- ~OCSPInitSingleton() {
+ virtual ~OCSPInitSingleton() {
request_context_ = NULL;
}
@@ -81,7 +84,8 @@ URLRequestContext* OCSPInitSingleton::request_context_ = NULL;
// 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;