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

Commit 5e26ad3b authored by Yu Shan's avatar Yu Shan
Browse files

Fix a bug that would access uninitialized data.

Fix a bug where mThread is initialized before mRequests, causing
the new thread to access uninitialized mRequests.

Test: None. This is a race condition depending on when the thread is
started and hard to reproduce.
Bug: 231647009

Change-Id: I68037125bf4d14846585bd3a038844e4a7ced377
parent 6a44f5ee
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -1339,11 +1339,15 @@ Result<std::vector<uint8_t>> FakeVehicleHardware::parseHexString(const std::stri
template <class CallbackType, class RequestType>
FakeVehicleHardware::PendingRequestHandler<CallbackType, RequestType>::PendingRequestHandler(
        FakeVehicleHardware* hardware)
    : mHardware(hardware), mThread([this] {
    : mHardware(hardware) {
    // Don't initialize mThread in initialization list because mThread depends on mRequests and we
    // want mRequests to be initialized first.
    mThread = std::thread([this] {
        while (mRequests.waitForItems()) {
            handleRequestsOnce();
        }
      }) {}
    });
}

template <class CallbackType, class RequestType>
void FakeVehicleHardware::PendingRequestHandler<CallbackType, RequestType>::addRequest(