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

Commit d9125699 authored by Ytai Ben-Tsvi's avatar Ytai Ben-Tsvi
Browse files

Fix handling of initialization error

When an error occurs before mLooper has been initialized, the dtor
will access uninitialized memory.
This change initializes mLooper first, to avoid this error.

Bug: 188502620
Test: Manual running of SensorPoseProvider-example
Change-Id: I0a493ff766f53d17a9a2679efed693df702ba92c
parent f7adf32d
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -144,6 +144,9 @@ class SensorPoseProviderImpl : public SensorPoseProvider {
    bool waitInitFinished() { return mInitPromise.get_future().get(); }

    void threadFunc(const char* packageName) {
        // Obtain looper.
        mLooper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS);

        // The number 19 is arbitrary, only useful if using multiple objects on the same looper.
        constexpr int kIdent = 19;

@@ -155,9 +158,6 @@ class SensorPoseProviderImpl : public SensorPoseProvider {
            return;
        }

        // Obtain looper.
        mLooper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS);

        // Create event queue.
        ASensorEventQueue* queue =
                ASensorManager_createEventQueue(sensor_manager, mLooper, kIdent, nullptr, nullptr);