Bug 1463494: delete the sensor observerlist array in a deferred manner r=froyd,jchen

clean up sensorlist if Dispatch fails
This commit is contained in:
Randell Jesup 2018-05-25 21:16:28 -04:00
Родитель db0ffdf2b9
Коммит 42686d4bdc
1 изменённых файлов: 17 добавлений и 2 удалений

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

@ -438,14 +438,29 @@ UnregisterSensorObserver(SensorType aSensor, ISensorObserver *aObserver) {
}
DisableSensorNotifications(aSensor);
// Destroy sSensorObservers only if all observer lists are empty.
for (int i = 0; i < NUM_SENSOR_TYPE; i++) {
if (gSensorObservers[i].Length() > 0) {
return;
}
}
delete [] gSensorObservers;
// We want to destroy gSensorObservers if all observer lists are
// empty, but we have to defer the deallocation via a runnable to
// mainthread (since we may be inside NotifySensorChange()/Broadcast()
// when it calls UnregisterSensorObserver()).
SensorObserverList* sensorlists = gSensorObservers;
gSensorObservers = nullptr;
// Unlike DispatchToMainThread, DispatchToCurrentThread doesn't leak a runnable if
// it fails (and we assert we're on MainThread).
if (NS_FAILED(NS_DispatchToCurrentThread(NS_NewRunnableFunction("UnregisterSensorObserver",
[sensorlists]() -> void {
delete [] sensorlists;
}))))
{
// Still need to delete sensorlists if the dispatch fails
delete [] sensorlists;
}
}
void