[Libreoffice-commits] core.git: sw/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Thu Jun 3 12:08:45 UTC 2021


 sw/source/uibase/inc/redlndlg.hxx  |    3 +++
 sw/source/uibase/misc/redlndlg.cxx |   19 +++++--------------
 2 files changed, 8 insertions(+), 14 deletions(-)

New commits:
commit 22bae1d412e241870d835c827abd6df5f9ac6ff8
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Thu Jun 3 13:04:21 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Thu Jun 3 14:08:04 2021 +0200

    fix leak in SwRedlineAcceptDlg
    
    Change-Id: I9d9f02af7708043fbf80eb04dd12ea57cb4aa628
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116653
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sw/source/uibase/inc/redlndlg.hxx b/sw/source/uibase/inc/redlndlg.hxx
index 63cfca9d9409..e07af66b3aa3 100644
--- a/sw/source/uibase/inc/redlndlg.hxx
+++ b/sw/source/uibase/inc/redlndlg.hxx
@@ -59,6 +59,9 @@ class SW_DLLPUBLIC SwRedlineAcceptDlg final
     std::vector<std::unique_ptr<SwRedlineDataParent>> m_RedlineParents;
     std::vector<std::unique_ptr<SwRedlineDataChild>>
                             m_RedlineChildren;
+    // purely here so we don't leak
+    std::vector<std::unique_ptr<RedlinData>>
+                            m_RedlinData;
     SwRedlineDataParentSortArr m_aUsedSeqNo;
     Timer                   m_aSelectTimer;
     OUString                m_sInserted;
diff --git a/sw/source/uibase/misc/redlndlg.cxx b/sw/source/uibase/misc/redlndlg.cxx
index a4937241fe00..bc334e1303ac 100644
--- a/sw/source/uibase/misc/redlndlg.cxx
+++ b/sw/source/uibase/misc/redlndlg.cxx
@@ -201,18 +201,6 @@ SwRedlineAcceptDlg::SwRedlineAcceptDlg(const std::shared_ptr<weld::Window>& rPar
 
 SwRedlineAcceptDlg::~SwRedlineAcceptDlg()
 {
-    weld::TreeView& rTreeView = m_pTable->GetWidget();
-    rTreeView.all_foreach(
-        [&rTreeView](weld::TreeIter& rEntry)
-        {
-            if (!rTreeView.get_iter_depth(rEntry))
-            {
-                RedlinData *pData = reinterpret_cast<RedlinData*>(rTreeView.get_id(rEntry).toInt64());
-                delete pData;
-            }
-            return false;
-        }
-    );
 }
 
 void SwRedlineAcceptDlg::Init(SwRedlineTable::size_type nStart)
@@ -227,6 +215,7 @@ void SwRedlineAcceptDlg::Init(SwRedlineTable::size_type nStart)
     else
     {
         rTreeView.clear();
+        m_RedlinData.clear();
         m_RedlineChildren.clear();
         m_RedlineParents.erase(m_RedlineParents.begin() + nStart, m_RedlineParents.end());
     }
@@ -597,9 +586,10 @@ void SwRedlineAcceptDlg::InsertChildren(SwRedlineDataParent *pParent, const SwRa
             OUString sComment = rRedln.GetComment(nStack);
 
             std::unique_ptr<weld::TreeIter> xChild(rTreeView.make_iterator());
-            OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pData.release())));
+            OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pData.get())));
             rTreeView.insert(pParent->xTLBParent.get(), -1, nullptr, &sId, nullptr, nullptr,
                              false, xChild.get());
+            m_RedlinData.push_back(std::move(pData));
 
             rTreeView.set_image(*xChild, sImage, -1);
             rTreeView.set_text(*xChild, sAuthor, 1);
@@ -768,9 +758,10 @@ void SwRedlineAcceptDlg::InsertParents(SwRedlineTable::size_type nStart, SwRedli
         pData->eType = rRedln.GetType(0);
         OUString sDateEntry = GetAppLangDateTimeString(pData->aDateTime);
 
-        OUString sId = OUString::number(reinterpret_cast<sal_Int64>(pData.release()));
+        OUString sId = OUString::number(reinterpret_cast<sal_Int64>(pData.get()));
         std::unique_ptr<weld::TreeIter> xParent(rTreeView.make_iterator());
         rTreeView.insert(nullptr, i, nullptr, &sId, nullptr, nullptr, false, xParent.get());
+        m_RedlinData.push_back(std::move(pData));
 
         rTreeView.set_image(*xParent, sImage, -1);
         rTreeView.set_text(*xParent, sAuthor, 1);


More information about the Libreoffice-commits mailing list