Commit 81a82eb2 authored by Randell Jesup's avatar Randell Jesup Committed by Pier Angelo Vendrame
Browse files

Bug 2036906: Fix CacheEntry::mDoomCallback data race r=necko-reviewers,valentin

parent 51ae80b3
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -504,7 +504,12 @@ NS_IMETHODIMP CacheEntry::OnFileReady(nsresult aResult, bool aIsNew) {
}

NS_IMETHODIMP CacheEntry::OnFileDoomed(nsresult aResult) {
  if (mDoomCallback) {
  bool doomCallback = false;
  {
    mozilla::MutexAutoLock lock(mLock);
    doomCallback = bool(mDoomCallback);
  }
  if (doomCallback) {
    RefPtr<DoomCallbackRunnable> event =
        new DoomCallbackRunnable(this, aResult);
    NS_DispatchToMainThread(event);
@@ -1760,8 +1765,12 @@ void CacheEntry::DoomFile() {
    }
  }

  // Always posts to the main thread.
  OnFileDoomed(rv);
  // mLock is already held; dispatch directly instead of calling
  // OnFileDoomed() which would deadlock re-acquiring it.
  if (mDoomCallback) {
    RefPtr<DoomCallbackRunnable> event = new DoomCallbackRunnable(this, rv);
    NS_DispatchToMainThread(event);
  }
}

void CacheEntry::RemoveForcedValidity() {
+1 −1
Original line number Diff line number Diff line
@@ -317,7 +317,7 @@ class CacheEntry final : public nsIRunnable,
  ::mozilla::ThreadSafeAutoRefCnt mHandlesCount MOZ_GUARDED_BY(mLock);

  nsTArray<Callback> mCallbacks MOZ_GUARDED_BY(mLock);
  nsCOMPtr<nsICacheEntryDoomCallback> mDoomCallback;
  nsCOMPtr<nsICacheEntryDoomCallback> mDoomCallback MOZ_GUARDED_BY(mLock);

  // Set in CacheEntry::Load(), only - shouldn't need to be under lock
  // XXX FIX?  is this correct?