Bug 1173573 - Fix possible crash initializing sessionstorage. r=honzab

This commit is contained in:
Blake Kaplan 2015-06-23 11:22:00 +02:00
parent 785d7bcf18
commit c32149f142
3 changed files with 22 additions and 1 deletions

View File

@ -771,8 +771,11 @@ DOMStorageCache::StartDatabase()
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)) {

View File

@ -628,6 +628,21 @@ 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()

View File

@ -126,6 +126,9 @@ public:
// 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;
};