mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-07 16:28:38 +09:00
Issue #2928 - Add extra checks to nsExpirationTracker.
Turn some asserts into early exits and add sanity checks. Also check main thread access for the fake mutex and report.
This commit is contained in:
parent
2cd0e956bd
commit
ad21e2d1f4
1 changed files with 18 additions and 3 deletions
|
|
@ -127,9 +127,15 @@ public:
|
|||
*/
|
||||
nsresult AddObjectLocked(T* aObj, const AutoLock& aAutoLock)
|
||||
{
|
||||
if (NS_WARN_IF(!aObj)) {
|
||||
// Invalid object to add
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
nsExpirationState* state = aObj->GetExpirationState();
|
||||
NS_ASSERTION(!state->IsTracked(),
|
||||
"Tried to add an object that's already tracked");
|
||||
if (NS_WARN_IF(state->IsTracked())) {
|
||||
// Tried to add an object that's already tracked.
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
nsTArray<T*>& generation = mGenerations[mNewestGeneration];
|
||||
uint32_t index = generation.Length();
|
||||
if (index > nsExpirationState::MAX_INDEX_IN_GENERATION) {
|
||||
|
|
@ -156,8 +162,15 @@ public:
|
|||
*/
|
||||
void RemoveObjectLocked(T* aObj, const AutoLock& aAutoLock)
|
||||
{
|
||||
if (NS_WARN_IF(!aObj)) {
|
||||
// Invalid object to remove
|
||||
return;
|
||||
}
|
||||
nsExpirationState* state = aObj->GetExpirationState();
|
||||
NS_ASSERTION(state->IsTracked(), "Tried to remove an object that's not tracked");
|
||||
if (NS_WARN_IF(!state->IsTracked())) {
|
||||
// Tried to remove an object that's not tracked
|
||||
return;
|
||||
}
|
||||
nsTArray<T*>& generation = mGenerations[state->mGeneration];
|
||||
uint32_t index = state->mIndexInGeneration;
|
||||
NS_ASSERTION(generation.Length() > index &&
|
||||
|
|
@ -458,11 +471,13 @@ class nsExpirationTracker : protected ::detail::SingleThreadedExpirationTracker<
|
|||
Lock mLock;
|
||||
|
||||
AutoLock FakeLock() {
|
||||
MOZ_DIAGNOSTIC_ASSERT(NS_IsMainThread());
|
||||
return AutoLock(mLock);
|
||||
}
|
||||
|
||||
Lock& GetMutex() override
|
||||
{
|
||||
MOZ_DIAGNOSTIC_ASSERT(NS_IsMainThread());
|
||||
return mLock;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue