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

Caolán McNamara caolanm at redhat.com
Thu Feb 1 14:26:37 UTC 2018


 sw/source/filter/html/htmltab.cxx |   21 ++++++++++++++-------
 sw/source/filter/html/swhtml.hxx  |    9 ++++-----
 2 files changed, 18 insertions(+), 12 deletions(-)

New commits:
commit 0e5d5389428accb397594229f173a9b95aef4433
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Thu Feb 1 14:23:03 2018 +0000

    ofz#5872 Direct-leak
    
    Change-Id: Id792ecc80dd3367f070c9a613f3999a8c3e386a1

diff --git a/sw/source/filter/html/htmltab.cxx b/sw/source/filter/html/htmltab.cxx
index 680f8c98c95b..b26a03d02ce1 100644
--- a/sw/source/filter/html/htmltab.cxx
+++ b/sw/source/filter/html/htmltab.cxx
@@ -401,7 +401,9 @@ class HTMLTable
 
     const SwStartNode *m_pPrevStartNode;   // the Table-Node or the Start-Node of the section before
     const SwTable *m_pSwTable;        // SW-Table (only on Top-Level)
-    SwTableBox* m_pBox1;                    // TableBox, generated when the Top-Level-Table was build
+public:
+    std::unique_ptr<SwTableBox> m_xBox1;    // TableBox, generated when the Top-Level-Table was build
+private:
     SwTableBoxFormat *m_pBoxFormat;         // frame::Frame-Format from SwTableBox
     SwTableLineFormat *m_pLineFormat;       // frame::Frame-Format from SwTableLine
     SwTableLineFormat *m_pLineFrameFormatNoHeight;
@@ -909,7 +911,6 @@ void HTMLTable::InitCtor(const HTMLTableOptions& rOptions)
     m_nRows = 0;
     m_nCurrentRow = 0; m_nCurrentColumn = 0;
 
-    m_pBox1 = nullptr;
     m_pBoxFormat = nullptr; m_pLineFormat = nullptr;
     m_pLineFrameFormatNoHeight = nullptr;
     m_xInheritedBackgroundBrush.reset();
@@ -1047,6 +1048,13 @@ HTMLTable::HTMLTable(SwHTMLParser* pPars,
     m_pParser->RegisterHTMLTable(this);
 }
 
+void SwHTMLParser::DeregisterHTMLTable(HTMLTable* pOld)
+{
+    if (pOld->m_xBox1)
+        m_aOrphanedTableBoxes.emplace_back(std::move(pOld->m_xBox1));
+    m_aTables.erase(std::remove(m_aTables.begin(), m_aTables.end(), pOld));
+}
+
 HTMLTable::~HTMLTable()
 {
     m_pParser->DeregisterHTMLTable(this);
@@ -1465,12 +1473,11 @@ SwTableBox *HTMLTable::NewTableBox( const SwStartNode *pStNd,
 {
     SwTableBox *pBox;
 
-    if (m_pBox1 && m_pBox1->GetSttNd() == pStNd)
+    if (m_xBox1 && m_xBox1->GetSttNd() == pStNd)
     {
         // If the StartNode is the StartNode of the initially created box, we take that box
-        pBox = const_cast<HTMLTable*>(this)->m_pBox1;
+        pBox = const_cast<HTMLTable*>(this)->m_xBox1.release();
         pBox->SetUpper(pUpper);
-        const_cast<HTMLTable*>(this)->m_pBox1 = nullptr;
     }
     else
         pBox = new SwTableBox( m_pBoxFormat, *pStNd, pUpper );
@@ -2316,11 +2323,11 @@ void HTMLTable::MakeTable( SwTableBox *pBox, sal_uInt16 nAbsAvail,
     // get the default line and box format
     // remember the first box and unlist it from the first row
     SwTableLine *pLine1 = (m_pSwTable->GetTabLines())[0];
-    m_pBox1 = (pLine1->GetTabBoxes())[0];
+    m_xBox1.reset((pLine1->GetTabBoxes())[0]);
     pLine1->GetTabBoxes().erase(pLine1->GetTabBoxes().begin());
 
     m_pLineFormat = static_cast<SwTableLineFormat*>(pLine1->GetFrameFormat());
-    m_pBoxFormat = static_cast<SwTableBoxFormat*>(m_pBox1->GetFrameFormat());
+    m_pBoxFormat = static_cast<SwTableBoxFormat*>(m_xBox1->GetFrameFormat());
 
     MakeTable_( pBox );
 
diff --git a/sw/source/filter/html/swhtml.hxx b/sw/source/filter/html/swhtml.hxx
index 812a4ba1cc62..585b42e07c03 100644
--- a/sw/source/filter/html/swhtml.hxx
+++ b/sw/source/filter/html/swhtml.hxx
@@ -406,6 +406,9 @@ class SwHTMLParser : public SfxHTMLParser, public SwClient
     HTMLAttrContexts m_aContexts;// the current context of attribute/token
     std::vector<SwFrameFormat *> m_aMoveFlyFrames;// Fly-Frames, the anchor is moved
     std::deque<sal_Int32> m_aMoveFlyCnts;// and the Content-Positions
+    //stray SwTableBoxes which need to be deleted to avoid leaking, but hold
+    //onto them until parsing is done
+    std::vector<std::unique_ptr<SwTableBox>> m_aOrphanedTableBoxes;
 
     SwApplet_Impl *m_pAppletImpl; // current applet
 
@@ -947,11 +950,7 @@ public:
         m_aTables.push_back(pNew);
     }
 
-    void DeregisterHTMLTable(HTMLTable* pOld)
-    {
-        m_aTables.erase(std::remove(m_aTables.begin(), m_aTables.end(), pOld));
-    }
-
+    void DeregisterHTMLTable(HTMLTable* pOld);
 };
 
 struct SwPendingStackData


More information about the Libreoffice-commits mailing list