From b6b28e58c421c12ca70c71d2f396e9ce11e2e5df Mon Sep 17 00:00:00 2001 From: Brian Duddie Date: Mon, 10 Jun 2019 09:14:14 -0700 Subject: [PATCH] Fix null deref in sensors 2.0 VTS teardown Avoid attempting to clean up resources that were never initialized, e.g. if the target device doesn't support the version of the HAL in question. Fixes: 134911861 Test: run VtsHalSensorsV2_0Target on device that only supports HAL v1.0 Change-Id: I6b529fae13b1347d533a19e04f1c7748bcda961b --- .../vts/functional/SensorsHidlEnvironmentV2_0.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/sensors/2.0/vts/functional/SensorsHidlEnvironmentV2_0.cpp b/sensors/2.0/vts/functional/SensorsHidlEnvironmentV2_0.cpp index be7415bb7c..5f71654e97 100644 --- a/sensors/2.0/vts/functional/SensorsHidlEnvironmentV2_0.cpp +++ b/sensors/2.0/vts/functional/SensorsHidlEnvironmentV2_0.cpp @@ -109,11 +109,15 @@ bool SensorsHidlEnvironmentV2_0::resetHal() { void SensorsHidlEnvironmentV2_0::HidlTearDown() { mStopThread = true; - // Wake up the event queue so the poll thread can exit - mEventQueueFlag->wake(asBaseType(EventQueueFlagBits::READ_AND_PROCESS)); - mPollThread.join(); + if (mEventQueueFlag != nullptr) { + // Wake up the event queue so the poll thread can exit + mEventQueueFlag->wake(asBaseType(EventQueueFlagBits::READ_AND_PROCESS)); + if (mPollThread.joinable()) { + mPollThread.join(); + } - EventFlag::deleteEventFlag(&mEventQueueFlag); + EventFlag::deleteEventFlag(&mEventQueueFlag); + } } void SensorsHidlEnvironmentV2_0::startPollingThread() {