Bug 1173573 - Fix possible crash initializing sessionstorage. r=honzab
authorBlake Kaplan <mrbkap@gmail.com>
Tue, 23 Jun 2015 11:22:00 +0200
changeset 250040 c76f4193401ba474edbfadcf392d5d6683e67ced
parent 250039 719a075603f4fe98432f98e88ffb9c337fd8e06e
child 250041 ec338746b491c38295590b1b45b2d223ba93f6a2
push id61426
push usercbook@mozilla.com
push dateWed, 24 Jun 2015 06:14:00 +0000
treeherdermozilla-inbound@ec338746b491 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershonzab
bugs1173573
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1173573 - Fix possible crash initializing sessionstorage. r=honzab
dom/storage/DOMStorageCache.cpp
dom/storage/DOMStorageManager.cpp
dom/storage/DOMStorageManager.h
--- a/dom/storage/DOMStorageCache.cpp
+++ b/dom/storage/DOMStorageCache.cpp
@@ -766,18 +766,21 @@ DOMStorageCache::StartDatabase()
 
     nsresult rv = db->Init();
     if (NS_FAILED(rv)) {
       return nullptr;
     }
 
     sDatabase = db.forget();
   } else {
+    // Use DOMLocalStorageManager::Ensure in case we're called from
+    // DOMSessionStorageManager's initializer and we haven't yet initialized the
+    // local storage manager.
     nsRefPtr<DOMStorageDBChild> db = new DOMStorageDBChild(
-        DOMLocalStorageManager::Self());
+        DOMLocalStorageManager::Ensure());
 
     nsresult rv = db->Init();
     if (NS_FAILED(rv)) {
       return nullptr;
     }
 
     db.forget(&sDatabase);
   }
--- a/dom/storage/DOMStorageManager.cpp
+++ b/dom/storage/DOMStorageManager.cpp
@@ -623,16 +623,31 @@ DOMLocalStorageManager::DOMLocalStorageM
   }
 }
 
 DOMLocalStorageManager::~DOMLocalStorageManager()
 {
   sSelf = nullptr;
 }
 
+DOMLocalStorageManager*
+DOMLocalStorageManager::Ensure()
+{
+  if (sSelf) {
+    return sSelf;
+  }
+
+  // Cause sSelf to be populated.
+  nsCOMPtr<nsIDOMStorageManager> initializer =
+    do_GetService("@mozilla.org/dom/localStorage-manager;1");
+  MOZ_ASSERT(sSelf, "Didn't initialize?");
+
+  return sSelf;
+}
+
 // DOMSessionStorageManager
 
 DOMSessionStorageManager::DOMSessionStorageManager()
   : DOMStorageManager(SessionStorage)
 {
   if (XRE_GetProcessType() != GeckoProcessType_Default) {
     // Do this only on the child process.  The thread IPC bridge
     // is also used to communicate chrome observer notifications.
--- a/dom/storage/DOMStorageManager.h
+++ b/dom/storage/DOMStorageManager.h
@@ -121,16 +121,19 @@ class DOMLocalStorageManager final : pub
 {
 public:
   DOMLocalStorageManager();
   virtual ~DOMLocalStorageManager();
 
   // Global getter of localStorage manager service
   static DOMLocalStorageManager* Self() { return sSelf; }
 
+  // Like Self, but creates an instance if we're not yet initialized.
+  static DOMLocalStorageManager* Ensure();
+
 private:
   static DOMLocalStorageManager* sSelf;
 };
 
 class DOMSessionStorageManager final : public DOMStorageManager
 {
 public:
   DOMSessionStorageManager();