From cac1f6fa80f3ea9206e39b07ed797730409dec02 Mon Sep 17 00:00:00 2001 From: Hosang Kim Date: Fri, 12 Apr 2024 19:44:32 +0900 Subject: [PATCH] AtspiAccessibleWatcher: fix memory leak If executeAndWaitForEvent is not called, mEventQueue is not freed. So it looks like memory leak. Change-Id: Ibe497fc6536b87df039e7d7a4c222cdc41716e00 --- .../inc/Impl/Accessibility/AtspiAccessibleWatcher.h | 1 + .../Impl/Accessibility/AtspiAccessibleWatcher.cc | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/libaurum/inc/Impl/Accessibility/AtspiAccessibleWatcher.h b/libaurum/inc/Impl/Accessibility/AtspiAccessibleWatcher.h index ad6e745..e751791 100644 --- a/libaurum/inc/Impl/Accessibility/AtspiAccessibleWatcher.h +++ b/libaurum/inc/Impl/Accessibility/AtspiAccessibleWatcher.h @@ -193,6 +193,7 @@ private: static IdleEventState isIdle; static int mRenderCount; static bool isWindowEventEmitted; + static bool mWaitingForEvent; }; } diff --git a/libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc b/libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc index 8c0c9f7..be37001 100644 --- a/libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc +++ b/libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc @@ -46,6 +46,7 @@ IdleEventState AtspiAccessibleWatcher::isIdle = IdleEventState::IDLE_LISTEN_READ static const unsigned int WAIT_FOR_IDLE_MILLI_SEC = 1000; // 1sec int AtspiAccessibleWatcher::mRenderCount = 10; bool AtspiAccessibleWatcher::isWindowEventEmitted = false; +bool AtspiAccessibleWatcher::mWaitingForEvent = false; static bool iShowingNode(AtspiAccessible *node) { @@ -301,7 +302,7 @@ void AtspiAccessibleWatcher::processCallback(char *type, char *name, char *pkg) { mMutex.lock(); auto a11yEvent = std::make_shared(std::string(type), std::string(name), std::string(pkg)); - mEventQueue.push_back(a11yEvent); + if (mWaitingForEvent) mEventQueue.push_back(a11yEvent); mMutex.unlock(); if (this->mHandlers.count(a11yEvent->getEvent())) { @@ -421,6 +422,7 @@ bool AtspiAccessibleWatcher::executeAndWaitForEvents(const Runnable *cmd, const { mMutex.lock(); mEventQueue.clear(); + mWaitingForEvent = true; mMutex.unlock(); // Call atspi method for start to listen atspi event. @@ -457,6 +459,10 @@ bool AtspiAccessibleWatcher::executeAndWaitForEvents(const Runnable *cmd, const if (COMPARE(type, event->getEvent()) && (packageName.empty() || packageName == event->getPkg())) { LOGI("type %d == %d name %s pkg %s",static_cast(type), static_cast(event->getEvent()), event->getName().c_str(), event->getPkg().c_str()); + mMutex.lock(); + mWaitingForEvent = false; + mEventQueue.clear(); + mMutex.unlock(); return true; } } @@ -468,6 +474,11 @@ bool AtspiAccessibleWatcher::executeAndWaitForEvents(const Runnable *cmd, const std::chrono::milliseconds{100}); } + mMutex.lock(); + mWaitingForEvent = false; + mEventQueue.clear(); + mMutex.unlock(); + if (isIdle != IdleEventState::IDLE_LISTEN_READY) { LOGI("RenderPost listen finish"); -- 2.34.1