Skip to content

Commit

Permalink
Bug 1463494: delete the sensor observerlist array in a deferred manne…
Browse files Browse the repository at this point in the history
…r r=froyd,jchen

clean up sensorlist if Dispatch fails
  • Loading branch information
jesup committed May 26, 2018
1 parent db0ffdf commit 42686d4
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions hal/Hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 42686d4

Please sign in to comment.