summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Arthur Ishiguro <arthuri@google.com> 2023-04-03 17:01:40 +0000
committer Arthur Ishiguro <arthuri@google.com> 2023-04-03 19:40:48 +0000
commit9f0f647ffbb76308a4bd610fa37dabfedf2ca154 (patch)
treed497d49cd61a79424a263ce468a14c04dd974a48
parent6d49710e8d198bf053ab0a4eb3e142bb47cedde2 (diff)
Perform cleanup operation on destroy()
In some cases, it's possible that the destructor of the SensorEventConnection object is never called, because unless the cleanupConnection() call is made, the SensorService still has a strong reference to the SensorEventConnection. This may result in leaked resources, because the connection still exists in the SensorService, though the connection has been destroyed from the client's perspective. This CL fixes this issue by doing the cleanup operation in the destroy() call instead. Bug: 274595196 Test: Run STS test, and verify all connections are destroyed afterwards Change-Id: I7edb72d17337420e19352874bcae1d36b5981b95
-rw-r--r--services/sensorservice/SensorEventConnection.cpp9
1 files changed, 4 insertions, 5 deletions
diff --git a/services/sensorservice/SensorEventConnection.cpp b/services/sensorservice/SensorEventConnection.cpp
index b94b1c0a1a..7a6b31d642 100644
--- a/services/sensorservice/SensorEventConnection.cpp
+++ b/services/sensorservice/SensorEventConnection.cpp
@@ -55,14 +55,13 @@ SensorService::SensorEventConnection::SensorEventConnection(
SensorService::SensorEventConnection::~SensorEventConnection() {
ALOGD_IF(DEBUG_CONNECTIONS, "~SensorEventConnection(%p)", this);
destroy();
- mService->cleanupConnection(this);
- if (mEventCache != nullptr) {
- delete[] mEventCache;
- }
+ delete[] mEventCache;
}
void SensorService::SensorEventConnection::destroy() {
- mDestroyed = true;
+ if (!mDestroyed.exchange(true)) {
+ mService->cleanupConnection(this);
+ }
}
void SensorService::SensorEventConnection::onFirstRef() {