Fix potential memory leak in bidirectional support. 86/318386/4
authorANZ1217 <chihun.jeong@samsung.com>
Thu, 16 Jan 2025 07:46:57 +0000 (16:46 +0900)
committerANZ1217 <chihun.jeong@samsung.com>
Fri, 17 Jan 2025 10:40:17 +0000 (19:40 +0900)
the leak occurs when DestroyInfo() called more than once with same index.

Change-Id: I103d0e74963b104a76e9a22695b992df3d9ae752

dali/internal/text/text-abstraction/bidirectional-support-impl.cpp

index 743946628917b9b52d2aa8ec0eb0a129a21911d6..54452f2d4ce7cde2f6d0ddca4241ddec11073e4d 100644 (file)
@@ -94,9 +94,13 @@ struct BidirectionalSupport::Plugin
     {
       BidirectionalInfo* info = *it;
 
-      free(info->embeddedLevels);
-      free(info->characterTypes);
-      free(info->bracketTypes);
+      if(info != nullptr)
+      {
+        free(info->embeddedLevels);
+        free(info->characterTypes);
+        free(info->bracketTypes);
+      }
+
       delete info;
     }
   }
@@ -164,7 +168,20 @@ struct BidirectionalSupport::Plugin
 
       mFreeIndices.Remove(it);
 
-      *(mParagraphBidirectionalInfo.Begin() + index) = bidirectionalInfo;
+      if(*(mParagraphBidirectionalInfo.Begin() + index) == nullptr)
+      {
+        *(mParagraphBidirectionalInfo.Begin() + index) = bidirectionalInfo;
+      }
+      else
+      {
+        DALI_LOG_ERROR("Attempted to overwrite a non-null pointer value.");
+
+        free(bidirectionalInfo->bracketTypes);
+        free(bidirectionalInfo->embeddedLevels);
+        free(bidirectionalInfo->characterTypes);
+        delete bidirectionalInfo;
+        return 0;
+      }
     }
     else
     {
@@ -196,10 +213,10 @@ struct BidirectionalSupport::Plugin
       delete bidirectionalInfo;
 
       *it = NULL;
-    }
 
-    // Add the index to the free indices vector.
-    mFreeIndices.PushBack(bidiInfoIndex);
+      // Add the index to the free indices vector.
+      mFreeIndices.PushBack(bidiInfoIndex);
+    }
   }
 
   void Reorder(BidiInfoIndex   bidiInfoIndex,