Bug 1395598 - Correct LocalStorage mozStorage misuse. r=janv, a=abillings
authorAndrew Sutherland <asutherland@asutherland.org>
Fri, 01 Sep 2017 10:32:59 -0400
changeset 423912 4e46cd56c813f0f31ea234e345ee022c5ec7840b
parent 423911 e65e640970ef101defb3e75fb4186741157c8b11
child 423913 da291ce74248b2830a0010a8bf21bba5f408bd43
push id1517
push userjlorenzo@mozilla.com
push dateThu, 14 Sep 2017 16:50:54 +0000
treeherdermozilla-release@3b41fd564418 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjanv, abillings
bugs1395598
milestone56.0
Bug 1395598 - Correct LocalStorage mozStorage misuse. r=janv, a=abillings
dom/storage/StorageDBThread.cpp
dom/storage/StorageIPC.cpp
--- a/dom/storage/StorageDBThread.cpp
+++ b/dom/storage/StorageDBThread.cpp
@@ -1086,18 +1086,20 @@ StorageDBThread::DBOperation::Perform(St
       nsAutoString value;
       rv = stmt->GetString(1, value);
       NS_ENSURE_SUCCESS(rv, rv);
 
       if (!mCache->LoadItem(key, value)) {
         break;
       }
     }
-
-    mCache->LoadDone(NS_OK);
+    // The loop condition's call to ExecuteStep() may have terminated because
+    // !NS_SUCCEEDED(), we need an early return to cover that case.  This also
+    // covers success cases as well, but that's inductively safe.
+    NS_ENSURE_SUCCESS(rv, rv);
     break;
   }
 
   case opGetUsage:
   {
     nsCOMPtr<mozIStorageStatement> stmt = aThread->mWorkerStatements.GetCachedStatement(
       "SELECT SUM(LENGTH(key) + LENGTH(value)) FROM webappsstore2 "
       "WHERE (originAttributes || ':' || originKey) LIKE :usageOrigin"
--- a/dom/storage/StorageIPC.cpp
+++ b/dom/storage/StorageIPC.cpp
@@ -664,32 +664,37 @@ public:
   }
   virtual const nsCString& OriginNoSuffix() const { return mOrigin; }
   virtual const nsCString& OriginSuffix() const { return mSuffix; }
   virtual bool Loaded() { return mLoaded; }
   virtual uint32_t LoadedCount() { return mLoadedCount; }
   virtual bool LoadItem(const nsAString& aKey, const nsString& aValue)
   {
     // Called on the aCache background thread
+    MOZ_ASSERT(!mLoaded);
     if (mLoaded) {
       return false;
     }
 
     ++mLoadedCount;
     mKeys->AppendElement(aKey);
     mValues->AppendElement(aValue);
     return true;
   }
 
   virtual void LoadDone(nsresult aRv)
   {
     // Called on the aCache background thread
     MonitorAutoLock monitor(mMonitor);
+    MOZ_ASSERT(!mLoaded && mRv);
     mLoaded = true;
-    *mRv = aRv;
+    if (mRv) {
+      *mRv = aRv;
+      mRv = nullptr;
+    }
     monitor.Notify();
   }
 
   virtual void LoadWait()
   {
     // Called on the main thread, exits after LoadDone() call
     MonitorAutoLock monitor(mMonitor);
     while (!mLoaded) {