$OpenBSD: patch-mozilla_security_manager_ssl_src_nsNSSComponent_cpp,v 1.9 2012/06/11 15:38:33 landry Exp $
--- mozilla/security/manager/ssl/src/nsNSSComponent.cpp.orig	Fri May 18 06:11:01 2012
+++ mozilla/security/manager/ssl/src/nsNSSComponent.cpp	Fri May 18 09:27:58 2012
@@ -111,6 +111,7 @@
 #include "secerr.h"
 #include "sslerr.h"
 #include "cert.h"
+#include "SSLServerCertVerification.h"
 
 #include "nsXULAppAPI.h"
 
@@ -124,6 +125,7 @@ extern "C" {
 }
 
 using namespace mozilla;
+using namespace mozilla::psm;
 
 #ifdef PR_LOGGING
 PRLogModuleInfo* gPIPNSSLog = nsnull;
@@ -395,6 +397,8 @@ nsNSSComponent::deleteBackgroundThreads()
     delete mCertVerificationThread;
     mCertVerificationThread = nsnull;
   }
+
+  StopSSLServerCertVerificationThreads();
 }
 
 void
@@ -402,21 +406,20 @@ nsNSSComponent::createBackgroundThreads()
 {
   NS_ASSERTION(mCertVerificationThread == nsnull,
                "Cert verification thread already created.");
-
   mCertVerificationThread = new nsCertVerificationThread;
   nsresult rv = mCertVerificationThread->startThread();
   if (NS_FAILED(rv)) {
     delete mCertVerificationThread;
     mCertVerificationThread = nsnull;
   }
+
+  InitializeSSLServerCertVerificationThreads();
 }
 
 nsNSSComponent::~nsNSSComponent()
 {
   PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsNSSComponent::dtor\n"));
 
-  deleteBackgroundThreads();
-
   if (mUpdateTimerInitialized) {
     {
       MutexAutoLock lock(mCrlTimerLock);
@@ -844,7 +847,7 @@ nsNSSComponent::InstallLoadableRoots()
 
     if (!possible_ckbi_locations[il])
     {
-      fullLibraryPath = PR_GetLibraryName(nsnull, "nssckbi");
+      fullLibraryPath = PR_GetLibraryName(NSS_LIBDIR, "nssckbi");
     }
     else
     {
@@ -1881,6 +1884,8 @@ nsNSSComponent::InitializeNSS(bool showWarningBox)
 
       LaunchSmartCardThreads();
 
+      createBackgroundThreads();
+
       PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("NSS Initialization done\n"));
     }
   }
@@ -2023,16 +2028,6 @@ nsNSSComponent::Init()
   if (mClientAuthRememberService)
     mClientAuthRememberService->Init();
 
-  createBackgroundThreads();
-  if (!mCertVerificationThread)
-  {
-    PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("NSS init, could not create threads\n"));
-
-    DeregisterObservers();
-    mPIPNSSBundle = nsnull;
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
-
   InitializeCRLUpdateTimer();
   RegisterPSMContentListener();
 
@@ -2247,6 +2242,7 @@ nsNSSComponent::Observe(nsISupports *aSubject, const c
     DoProfileChangeTeardown(aSubject);
   }
   else if (nsCRT::strcmp(aTopic, PROFILE_CHANGE_TEARDOWN_VETO_TOPIC) == 0) {
+    createBackgroundThreads();
     mShutdownObjectList->allowUI();
   }
   else if (nsCRT::strcmp(aTopic, PROFILE_BEFORE_CHANGE_TOPIC) == 0) {
@@ -2294,6 +2290,7 @@ nsNSSComponent::Observe(nsISupports *aSubject, const c
     InitializeCRLUpdateTimer();
   }
   else if (nsCRT::strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID) == 0) {
+    ShutdownSSLServerCertVerification();
 
     PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsNSSComponent: XPCom shutdown observed\n"));
 
@@ -2584,6 +2581,9 @@ nsNSSComponent::DoProfileChangeNetTeardown()
 void
 nsNSSComponent::DoProfileChangeTeardown(nsISupports* aSubject)
 {
+  /* XXX this doesn't work well, since nothing expects null pointers */
+  deleteBackgroundThreads();
+
   bool callVeto = false;
 
   if (!mShutdownObjectList->ifPossibleDisallowUI()) {
@@ -2637,9 +2637,6 @@ nsNSSComponent::DoProfileBeforeChange(nsISupports* aSu
 void
 nsNSSComponent::DoProfileChangeNetRestore()
 {
-  /* XXX this doesn't work well, since nothing expects null pointers */
-  deleteBackgroundThreads();
-  createBackgroundThreads();
   mIsNetworkDown = false;
 }
 
