зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
db0ffdf2b9
Коммит
42686d4bdc
19
hal/Hal.cpp
19
hal/Hal.cpp
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче