diff --git a/image/src/SurfaceCache.cpp b/image/src/SurfaceCache.cpp index 944bfb01438..56c4979c816 100644 --- a/image/src/SurfaceCache.cpp +++ b/image/src/SurfaceCache.cpp @@ -12,6 +12,7 @@ #include #include "mozilla/Attributes.h" // for MOZ_THIS_IN_INITIALIZER_LIST #include "mozilla/DebugOnly.h" +#include "mozilla/Likely.h" #include "mozilla/Move.h" #include "mozilla/RefPtr.h" #include "mozilla/StaticPtr.h" @@ -385,6 +386,8 @@ public: MOZ_ASSERT(mLockedCost <= mMaxCost, "Locked more than we can hold?"); } else { mCosts.InsertElementSorted(costEntry); + // This may fail during XPCOM shutdown, so we need to ensure the object is + // tracked before calling RemoveObject in StopTracking. mExpirationTracker.AddObject(aSurface); } } @@ -401,7 +404,14 @@ public: MOZ_ASSERT(!mCosts.Contains(costEntry), "Shouldn't have a cost entry for a locked surface"); } else { - mExpirationTracker.RemoveObject(aSurface); + if (MOZ_LIKELY(aSurface->GetExpirationState()->IsTracked())) { + mExpirationTracker.RemoveObject(aSurface); + } else { + // Our call to AddObject must have failed in StartTracking; most likely + // we're in XPCOM shutdown right now. + NS_WARNING("Not expiration-tracking an unlocked surface!"); + } + DebugOnly foundInCosts = mCosts.RemoveElementSorted(costEntry); MOZ_ASSERT(foundInCosts, "Lost track of costs for this surface"); }