bug 1444265 - break a potential cycle in BackgroundFileSaver to prevent leaks r=jduell

BackgroundFileSaver holds a reference to its nsIBackgroundFileSaverObserver
(observer). If such an observer has an enclosure that captures the
BackgroundFileSaver itself (as in test_backgroundfilesaver.js), this causes a
cycle that won't be caught by the cycle collector. Thus, we have to manually
break the cycle when we're done with the observer (in
BackgroundFileSaver::NotifySaveComplete). Note that this currently relies on the
fact that this implementation requires that Finish always be called (see remarks
in nsIBackgroundFileSaver.idl).

MozReview-Commit-ID: GOO9q2vFRso

--HG--
extra : rebase_source : f62b0ec513e0b681da3e76c0af31077d2fa03fea
extra : amend_source : 2b3a11d4b17df10705bad38e02b6ce130b456448
This commit is contained in:
David Keeler 2018-03-14 15:02:49 -07:00
Родитель 60df3274c7
Коммит aa1464d4a7
1 изменённых файлов: 4 добавлений и 0 удалений

Просмотреть файл

@ -755,6 +755,10 @@ BackgroundFileSaver::NotifySaveComplete()
if (mObserver) {
(void)mObserver->OnSaveComplete(this, status);
// If mObserver keeps alive an enclosure that captures `this`, we'll have a
// cycle that won't be caught by the cycle-collector, so we need to break it
// when we're done here (see bug 1444265).
mObserver = nullptr;
}
// At this point, the worker thread will not process any more events, and we