sw/source/core/text/porlay.cxx |   25 ++++++++++++++++++++++++-
 sw/source/core/text/porlay.hxx |    1 +
 2 files changed, 25 insertions(+), 1 deletion(-)

New commits:
commit 8347f43707ca1dc4f79dbaf3d5136f35067a6e6d
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Tue Jul 24 11:40:33 2018 +0100
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Tue Jul 24 14:42:50 2018 +0200

    forcepoint#52 flatten deep recursive delete of SwLineLayout
    
    Change-Id: I36d995062f4677ae900009d1eb5d48b906a4b36f
    Reviewed-on: https://gerrit.libreoffice.org/57910
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>
    Tested-by: Caolán McNamara <caol...@redhat.com>

diff --git a/sw/source/core/text/porlay.cxx b/sw/source/core/text/porlay.cxx
index e6b2ea0ee5a1..843d09c231b8 100644
--- a/sw/source/core/text/porlay.cxx
+++ b/sw/source/core/text/porlay.cxx
@@ -171,6 +171,29 @@ static  bool lcl_HasStrongLTR ( const OUString& rText, 
sal_Int32 nStart, sal_Int
      return false;
  }
 
+// This is (meant to be) functionally equivalent to 'delete m_pNext' where
+// deleting a SwLineLayout recursively deletes the owned m_pNext SwLineLayout.
+//
+// Here, instead of using a potentially deep stack, iterate over all the
+// SwLineLayouts that would be deleted recursively and delete them linearly
+void SwLineLayout::DeleteNext()
+{
+    if (!m_pNext)
+        return;
+    std::vector<SwLineLayout*> aNexts;
+    SwLineLayout* pNext = m_pNext;
+    do
+    {
+        aNexts.push_back(pNext);
+        SwLineLayout* pLastNext = pNext;
+        pNext = pNext->GetNext();
+        pLastNext->SetNext(nullptr);
+    }
+    while (pNext);
+    for (auto a : aNexts)
+        delete a;
+}
+
 // class SwLineLayout: This is the layout of a single line, which is made
 // up of its dimension, the character count and the word spacing in the line.
 // Line objects are managed in an own pool, in order to store them continuously
@@ -178,7 +201,7 @@ static  bool lcl_HasStrongLTR ( const OUString& rText, 
sal_Int32 nStart, sal_Int
 SwLineLayout::~SwLineLayout()
 {
     Truncate();
-    delete m_pNext;
+    DeleteNext();
     if( pBlink )
         pBlink->Delete( this );
     m_pLLSpaceAdd.reset();
diff --git a/sw/source/core/text/porlay.hxx b/sw/source/core/text/porlay.hxx
index 1ebf00cc0c0d..bffa35c692e8 100644
--- a/sw/source/core/text/porlay.hxx
+++ b/sw/source/core/text/porlay.hxx
@@ -102,6 +102,7 @@ private:
 
     SwTwips GetHangingMargin_() const;
 
+    void DeleteNext();
 public:
     // From SwLinePortion
     virtual SwLinePortion *Insert( SwLinePortion *pPortion ) override;
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to