Bug 1718415 - GetMainThreadIdleScheduler checks if scheduler is destroyed r=smaug

If GetMainThreadIdleScheduler is called after IPC is destroyed it can
attempt to start it as if it's the first use, which crashes. Instead check
if we've already destroyed the scheduler once and if so then return early.

Differential Revision: https://phabricator.services.mozilla.com/D119251
This commit is contained in:
Paul Bone 2021-07-07 23:43:01 +00:00
Родитель ff55286ec5
Коммит 5cbb4adf3a
2 изменённых файлов: 8 добавлений и 0 удалений

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

@ -15,10 +15,12 @@
namespace mozilla::ipc {
static IdleSchedulerChild* sMainThreadIdleScheduler = nullptr;
static bool sIdleSchedulerDestroyed = false;
IdleSchedulerChild::~IdleSchedulerChild() {
if (sMainThreadIdleScheduler == this) {
sMainThreadIdleScheduler = nullptr;
sIdleSchedulerDestroyed = true;
}
MOZ_ASSERT(!mIdlePeriodState);
}
@ -112,6 +114,10 @@ IdleSchedulerChild* IdleSchedulerChild::GetMainThreadIdleScheduler() {
return sMainThreadIdleScheduler;
}
if (sIdleSchedulerDestroyed) {
return nullptr;
}
ipc::PBackgroundChild* background =
ipc::BackgroundChild::GetOrCreateForCurrentThread();
if (background) {

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

@ -45,6 +45,8 @@ class IdleSchedulerChild final : public PIdleSchedulerChild {
void DoneGC();
// Returns nullptr if this is the parent process or the IdleSchedulerChild has
// already been destroyed, eg if IPC is shutting down.
static IdleSchedulerChild* GetMainThreadIdleScheduler();
private: