summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Matt Buckley <mattbuckley@google.com> 2023-08-24 15:56:46 +0000
committer Matt Buckley <mattbuckley@google.com> 2023-08-24 23:46:17 +0000
commitac620f64a32500890007b0b405ca72405d6db41e (patch)
tree711c95782d253880e7250f6b2d25e15d74d8e140
parent5e309ba6abbb0e4c1fd2fca834b213d5af220c2b (diff)
Fix possible leaks in CanvasContext HintSessionWrapper
Ensure the mHintSessionFuture is accounted for correctly in the destructor, and proper destruction is taken in CanvasContext::destroy() in addition to the destructor. Bug: b/297230599 Test: manual Change-Id: Idcbd0f2ba87290f090d693f0a64cb46fe8270b95
-rw-r--r--libs/hwui/renderthread/CanvasContext.cpp2
-rw-r--r--libs/hwui/renderthread/HintSessionWrapper.cpp9
-rw-r--r--libs/hwui/renderthread/HintSessionWrapper.h1
3 files changed, 12 insertions, 0 deletions
diff --git a/libs/hwui/renderthread/CanvasContext.cpp b/libs/hwui/renderthread/CanvasContext.cpp
index 4064bb933491..120d812d3480 100644
--- a/libs/hwui/renderthread/CanvasContext.cpp
+++ b/libs/hwui/renderthread/CanvasContext.cpp
@@ -162,6 +162,7 @@ void CanvasContext::destroy() {
destroyHardwareResources();
mAnimationContext->destroy();
mRenderThread.cacheManager().onContextStopped(this);
+ mHintSessionWrapper.destroy();
}
static void setBufferCount(ANativeWindow* window) {
@@ -195,6 +196,7 @@ void CanvasContext::setHardwareBuffer(AHardwareBuffer* buffer) {
void CanvasContext::setSurface(ANativeWindow* window, bool enableTimeout) {
ATRACE_CALL();
+ startHintSession();
if (window) {
mNativeSurface = std::make_unique<ReliableSurface>(window);
mNativeSurface->init();
diff --git a/libs/hwui/renderthread/HintSessionWrapper.cpp b/libs/hwui/renderthread/HintSessionWrapper.cpp
index 814ac4d90028..1f338ee523eb 100644
--- a/libs/hwui/renderthread/HintSessionWrapper.cpp
+++ b/libs/hwui/renderthread/HintSessionWrapper.cpp
@@ -93,8 +93,17 @@ HintSessionWrapper::HintSessionWrapper(pid_t uiThreadId, pid_t renderThreadId)
: mUiThreadId(uiThreadId), mRenderThreadId(renderThreadId) {}
HintSessionWrapper::~HintSessionWrapper() {
+ destroy();
+}
+
+void HintSessionWrapper::destroy() {
+ if (mHintSessionFuture.valid()) {
+ mHintSession = mHintSessionFuture.get();
+ }
if (mHintSession) {
gAPH_closeSessionFn(mHintSession);
+ mSessionValid = true;
+ mHintSession = nullptr;
}
}
diff --git a/libs/hwui/renderthread/HintSessionWrapper.h b/libs/hwui/renderthread/HintSessionWrapper.h
index 24b8150dd489..bdb9959b1ca7 100644
--- a/libs/hwui/renderthread/HintSessionWrapper.h
+++ b/libs/hwui/renderthread/HintSessionWrapper.h
@@ -37,6 +37,7 @@ public:
void sendLoadResetHint();
void sendLoadIncreaseHint();
bool init();
+ void destroy();
private:
APerformanceHintSession* mHintSession = nullptr;