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
  • Loading branch information
jesup committed May 24, 2018
1 parent 5cf7331 commit 5cfa62f
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions hal/Hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,14 +438,23 @@ 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;

NS_DispatchToMainThread(NS_NewRunnableFunction("UnregisterSensorObserver",
[sensorlists]() -> void {
delete [] sensorlists;
}));
}

void
Expand Down

0 comments on commit 5cfa62f

Please sign in to comment.