Bug 1339588 - Part 2: Help prevent nullptr crashes due to misuse of the timer API. r=froydnj

MozReview-Commit-ID: BXCGYWnFqSj
This commit is contained in:
Byron Campen [:bwc]
2017-02-14 16:27:33 -06:00
parent fa83d433b9
commit 33320c7805

View File

@@ -434,6 +434,7 @@ nsTimerImpl::Fire(int32_t aGeneration)
uint8_t oldType;
uint32_t oldDelay;
TimeStamp oldTimeout;
nsCOMPtr<nsITimer> kungFuDeathGrip;
{
// Don't fire callbacks or fiddle with refcounts when the mutex is locked.
@@ -447,6 +448,10 @@ nsTimerImpl::Fire(int32_t aGeneration)
oldType = mType;
oldDelay = mDelay;
oldTimeout = mTimeout;
// Ensure that the nsITimer does not unhook from the nsTimerImpl during
// Fire; this will cause null pointer crashes if the user of the timer drops
// its reference, and then uses the nsITimer* passed in the callback.
kungFuDeathGrip = mITimer;
}
PROFILER_LABEL("Timer", "Fire",