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

Commit b41e87ae authored by Martijn Coenen's avatar Martijn Coenen
Browse files

SensorService: fix potential mutex use-before-init.

Since mRegistered is declared before mLock, it's possible to
receive a service notification callback on a binder thread
before mLock has been initialized. Prevent this by registering
in the constructor body, when we are guaranteed that the mutex
has been initialized.

Bug: 68765551
Test: many reboots on sailfish
Change-Id: I7beedc72be2a4aae961c546402f7016eacaeb3c0
parent bf26c166
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -28,8 +28,8 @@ using namespace android::hardware::sensors::V1_0;
namespace android {
namespace SensorDeviceUtils {

HidlServiceRegistrationWaiter::HidlServiceRegistrationWaiter()
        : mRegistered(ISensors::registerForNotifications("default", this)) {
HidlServiceRegistrationWaiter::HidlServiceRegistrationWaiter() {
    mRegistered = ISensors::registerForNotifications("default", this);
}

Return<void> HidlServiceRegistrationWaiter::onRegistration(
+1 −1
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ public:
     */
    bool wait();
private:
    const bool mRegistered;
    bool mRegistered;

    std::mutex mLock;
    std::condition_variable mCondition;