AtspiAccessibleWatcher: fix memory leak
authorHosang Kim <hosang12.kim@samsung.com>
Fri, 12 Apr 2024 10:44:32 +0000 (19:44 +0900)
committerHosang Kim <hosang12.kim@samsung.com>
Mon, 22 Apr 2024 07:43:07 +0000 (16:43 +0900)
If executeAndWaitForEvent is not called, mEventQueue is not freed.
So it looks like memory leak.

Change-Id: Ibe497fc6536b87df039e7d7a4c222cdc41716e00

libaurum/inc/Impl/Accessibility/AtspiAccessibleWatcher.h
libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc

index ad6e745..e751791 100644 (file)
@@ -193,6 +193,7 @@ private:
     static IdleEventState isIdle;
     static int mRenderCount;
     static bool isWindowEventEmitted;
+    static bool mWaitingForEvent;
 };
 
 }
index 8c0c9f7..be37001 100644 (file)
@@ -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<A11yEventInfo>(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<int>(type), static_cast<int>(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");