Bug 1136857 - Make DOMStorageCache::mLoaded flag atomic to prevent potential races, r=nfroyd

This commit is contained in:
Honza Bambas 2016-02-02 06:43:00 +01:00
parent e0a3306fdd
commit 5e22931312
2 changed files with 13 additions and 4 deletions

View File

@ -564,9 +564,16 @@ DOMStorageCache::Clear(const DOMStorage* aStorage)
void
DOMStorageCache::CloneFrom(const DOMStorageCache* aThat)
{
mLoaded = aThat->mLoaded;
// This will never be called on anything else than SessionStorage.
// This means mData will never be touched on any other thread than
// the main thread and it never went through the loading process.
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!mPersistent);
MOZ_ASSERT(!(bool)aThat->mLoaded);
mLoaded = false;
mInitialized = aThat->mInitialized;
mPersistent = aThat->mPersistent;
mPersistent = false;
mSessionOnlyDataSetActive = aThat->mSessionOnlyDataSetActive;
for (uint32_t i = 0; i < kDataSetCount; ++i) {

View File

@ -15,6 +15,7 @@
#include "nsHashKeys.h"
#include "mozilla/Monitor.h"
#include "mozilla/Telemetry.h"
#include "mozilla/Atomics.h"
#include "nsAutoPtr.h"
namespace mozilla {
@ -220,8 +221,9 @@ private:
// Flag that is initially false. When the cache is about to work with
// the database (i.e. it is persistent) this flags is set to true after
// all keys and coresponding values are loaded from the database.
// This flag never goes from true back to false.
bool mLoaded;
// This flag never goes from true back to false. Since this flag is
// critical for mData hashtable synchronization, it's made atomic.
Atomic<bool, ReleaseAcquire> mLoaded;
// Result of load from the database. Valid after mLoaded flag has been set.
nsresult mLoadResult;