Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 04b9c2c6 authored by Madhav Iyengar's avatar Madhav Iyengar
Browse files

Fixes possible race in example Sensors HAL

Fixes race condition where wake() is invoked on a possibly null
mEventQueueFlag.

Bug: 350489722
Test: presubmit
Change-Id: Ic6f98c099579a4fced30a5fc710f43fad1b8b7b9
parent 50e00412
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -97,9 +97,13 @@ class Sensors : public BnSensors, public ISensorsEventCallback {
            return;
        }
        if (mEventQueue->write(&events.front(), events.size())) {
            if (mEventQueueFlag == nullptr) {
                // Don't take the wake lock if we can't wake the receiver to avoid holding it
                // indefinitely.
                return;
            }
            mEventQueueFlag->wake(
                    static_cast<uint32_t>(BnSensors::EVENT_QUEUE_FLAG_BITS_READ_AND_PROCESS));

            if (wakeup) {
                // Keep track of the number of outstanding WAKE_UP events in order to properly hold
                // a wake lock until the framework has secured a wake lock