diff --git a/sensors/aidl/default/include/sensors-impl/Sensors.h b/sensors/aidl/default/include/sensors-impl/Sensors.h index e270d9682e..2adbc9dfb4 100644 --- a/sensors/aidl/default/include/sensors-impl/Sensors.h +++ b/sensors/aidl/default/include/sensors-impl/Sensors.h @@ -119,6 +119,8 @@ class Sensors : public BnSensors, public ISensorsEventCallback { // Utility function to delete the Event Flag void deleteEventFlag() { + // Hold the lock to ensure we don't delete the flag while it's being used in postEvents() + std::lock_guard lock(mWriteLock); if (mEventQueueFlag != nullptr) { status_t status = EventFlag::deleteEventFlag(&mEventQueueFlag); if (status != OK) {