Bug 1325119 - Assert that Init() has been called before DataStorage::WaitForReady() is called; r=keeler
authorEhsan Akhgari <ehsan@mozilla.com>
Wed, 21 Dec 2016 12:28:01 -0500
changeset 452614 b6fc4e878493f949125b6adae8a7b0ed1628d44f
parent 452495 ab439ec85d1556fdeaf5aafb5261bfa452a69f4e
child 452615 3f3ea09dd51190713ed8023d3f7543ad5bf7fa90
push id39420
push userbmo:ntim.bugs@gmail.com
push dateWed, 21 Dec 2016 21:04:18 +0000
reviewerskeeler
bugs1325119
milestone53.0a1
Bug 1325119 - Assert that Init() has been called before DataStorage::WaitForReady() is called; r=keeler
security/manager/ssl/DataStorage.cpp
security/manager/ssl/DataStorage.h
--- a/security/manager/ssl/DataStorage.cpp
+++ b/security/manager/ssl/DataStorage.cpp
@@ -418,16 +418,18 @@ DataStorage::AsyncReadData(bool& aHavePr
 
   aHaveProfileDir = true;
   return NS_OK;
 }
 
 void
 DataStorage::WaitForReady()
 {
+  MOZ_DIAGNOSTIC_ASSERT(mInitCalled, "Waiting before Init() has been called?");
+
   MonitorAutoLock readyLock(mReadyMonitor);
   while (!mReady) {
     nsresult rv = readyLock.Wait();
     if (NS_WARN_IF(NS_FAILED(rv))) {
       break;
     }
   }
   MOZ_ASSERT(mReady);
--- a/security/manager/ssl/DataStorage.h
+++ b/security/manager/ssl/DataStorage.h
@@ -2,16 +2,17 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_DataStorage_h
 #define mozilla_DataStorage_h
 
+#include "mozilla/Atomics.h"
 #include "mozilla/Monitor.h"
 #include "mozilla/Mutex.h"
 #include "mozilla/StaticPtr.h"
 #include "nsCOMPtr.h"
 #include "nsDataHashtable.h"
 #include "nsIObserver.h"
 #include "nsIThread.h"
 #include "nsITimer.h"
@@ -181,17 +182,17 @@ private:
   DataStorageTable  mTemporaryDataTable;
   DataStorageTable  mPrivateDataTable;
   nsCOMPtr<nsIThread> mWorkerThread;
   nsCOMPtr<nsIFile> mBackingFile;
   nsCOMPtr<nsITimer> mTimer; // All uses after init must be on the worker thread
   uint32_t mTimerDelay; // in milliseconds
   bool mPendingWrite; // true if a write is needed but hasn't been dispatched
   bool mShuttingDown;
-  bool mInitCalled; // Indicates that Init() has been called.
+  mozilla::Atomic<bool> mInitCalled; // Indicates that Init() has been called.
   // (End list of members protected by mMutex)
 
   Monitor mReadyMonitor; // Do not acquire this at the same time as mMutex.
   bool mReady; // Indicates that saved data has been read and Get can proceed.
 
   const nsString mFilename;
 
   static StaticAutoPtr<DataStorages> sDataStorages;