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

Caolán McNamara caolanm at redhat.com
Tue Dec 12 09:03:20 UTC 2017


 sw/source/filter/html/htmlcss1.cxx      |   13 +-
 sw/source/filter/html/htmlctxt.cxx      |   13 --
 sw/source/filter/html/htmlform.cxx      |   26 +---
 sw/source/filter/html/htmlgrin.cxx      |   17 +-
 sw/source/filter/html/htmlnumreader.cxx |   42 +++---
 sw/source/filter/html/htmlsect.cxx      |   50 +++-----
 sw/source/filter/html/htmltab.cxx       |   49 +++-----
 sw/source/filter/html/swhtml.cxx        |  196 +++++++++++++++-----------------
 sw/source/filter/html/swhtml.hxx        |   14 --
 9 files changed, 202 insertions(+), 218 deletions(-)

New commits:
commit 2c51c972c660abb2410cfdc914034e13460a23ae
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Mon Dec 11 16:37:23 2017 +0000

    ofz: more leaks
    
    Change-Id: Ibad2b1e0506d39411687e4a64d2c0bccb6e7d98f
    Reviewed-on: https://gerrit.libreoffice.org/46252
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/sw/source/filter/html/htmlcss1.cxx b/sw/source/filter/html/htmlcss1.cxx
index 45c7c86b5283..fa4e9a4951b8 100644
--- a/sw/source/filter/html/htmlcss1.cxx
+++ b/sw/source/filter/html/htmlcss1.cxx
@@ -2111,8 +2111,10 @@ void SwHTMLParser::SetFrameFormatAttrs( SfxItemSet &rItemSet,
     }
 }
 
-HTMLAttrContext *SwHTMLParser::PopContext( HtmlTokenId nToken )
+std::unique_ptr<HTMLAttrContext> SwHTMLParser::PopContext( HtmlTokenId nToken )
 {
+    std::unique_ptr<HTMLAttrContext> xCntxt;
+
     HTMLAttrContexts::size_type nPos = m_aContexts.size();
     if( nPos <= m_nContextStMin )
         return nullptr;
@@ -2140,14 +2142,13 @@ HTMLAttrContext *SwHTMLParser::PopContext( HtmlTokenId nToken )
         nPos--;
     }
 
-    HTMLAttrContext *pCntxt = nullptr;
     if( bFound )
     {
-        pCntxt = m_aContexts[nPos];
+        xCntxt = std::move(m_aContexts[nPos]);
         m_aContexts.erase( m_aContexts.begin() + nPos );
     }
 
-    return pCntxt;
+    return xCntxt;
 }
 
 bool SwHTMLParser::GetMarginsFromContext( sal_uInt16& nLeft,
@@ -2166,7 +2167,7 @@ bool SwHTMLParser::GetMarginsFromContext( sal_uInt16& nLeft,
 
     while( nPos > m_nContextStAttrMin )
     {
-        const HTMLAttrContext *pCntxt = m_aContexts[--nPos];
+        const HTMLAttrContext *pCntxt = m_aContexts[--nPos].get();
         if( pCntxt->IsLRSpaceChanged() )
         {
             pCntxt->GetMargins( nLeft, nRight, nIndent );
@@ -2202,7 +2203,7 @@ void SwHTMLParser::GetULSpaceFromContext( sal_uInt16& nUpper,
     HTMLAttrContexts::size_type nPos = m_aContexts.size();
     while( nPos > m_nContextStAttrMin )
     {
-        const HTMLAttrContext *pCntxt = m_aContexts[--nPos];
+        const HTMLAttrContext *pCntxt = m_aContexts[--nPos].get();
         if( pCntxt->IsULSpaceChanged() )
         {
             pCntxt->GetULSpace( nUpper, nLower );
diff --git a/sw/source/filter/html/htmlctxt.cxx b/sw/source/filter/html/htmlctxt.cxx
index f93e5ffee1d0..91b7384c844d 100644
--- a/sw/source/filter/html/htmlctxt.cxx
+++ b/sw/source/filter/html/htmlctxt.cxx
@@ -322,14 +322,13 @@ void SwHTMLParser::EndContext( HTMLAttrContext *pContext )
         // Close all still open contexts. Our own context needs to be deleted already!
         while( m_aContexts.size() > m_nContextStMin )
         {
-            HTMLAttrContext *pCntxt = PopContext();
-            OSL_ENSURE( pCntxt != pContext,
+            std::unique_ptr<HTMLAttrContext> xCntxt(PopContext());
+            OSL_ENSURE(xCntxt.get() != pContext,
                     "Context still on the stack" );
-            if( pCntxt == pContext )
+            if (xCntxt.get() == pContext)
                 break;
 
-            EndContext( pCntxt );
-            delete pCntxt;
+            EndContext(xCntxt.get());
         }
     }
 
@@ -493,7 +492,7 @@ void SwHTMLParser::InsertAttrs( SfxItemSet &rItemSet,
         m_pCSS1Parser->SetFormatBreak( rItemSet, rPropInfo );
 
     OSL_ENSURE(m_aContexts.size() <= m_nContextStAttrMin ||
-            m_aContexts.back() != pContext,
+            m_aContexts.back().get() != pContext,
             "SwHTMLParser::InsertAttrs: Context already on the Stack");
 
     SfxItemIter aIter( rItemSet );
@@ -516,7 +515,7 @@ void SwHTMLParser::InsertAttrs( SfxItemSet &rItemSet,
                 sal_uInt16 nOldLeft = 0, nOldRight = 0;
                 short nOldIndent = 0;
                 bool bIgnoreTop = m_aContexts.size() > m_nContextStMin &&
-                                  m_aContexts.back() == pContext;
+                                  m_aContexts.back().get() == pContext;
                 GetMarginsFromContext( nOldLeft, nOldRight, nOldIndent,
                                        bIgnoreTop  );
 
diff --git a/sw/source/filter/html/htmlform.cxx b/sw/source/filter/html/htmlform.cxx
index 988f7503d55c..1c762f262086 100644
--- a/sw/source/filter/html/htmlform.cxx
+++ b/sw/source/filter/html/htmlform.cxx
@@ -2064,11 +2064,11 @@ void SwHTMLParser::NewTextArea()
         SetControlSize( xShape, aTextSz, false, false );
 
     // create new context
-    HTMLAttrContext *pCntxt = new HTMLAttrContext( HtmlTokenId::TEXTAREA_ON );
+    std::unique_ptr<HTMLAttrContext> xCntxt(new HTMLAttrContext(HtmlTokenId::TEXTAREA_ON));
 
     // temporarily disable PRE/Listing/XMP
-    SplitPREListingXMP( pCntxt );
-    PushContext( pCntxt );
+    SplitPREListingXMP(xCntxt.get());
+    PushContext(xCntxt);
 
     m_bTextArea = true;
     m_bTAIgnoreNewPara = true;
@@ -2091,12 +2091,11 @@ void SwHTMLParser::EndTextArea()
     m_pFormImpl->ReleaseFCompPropSet();
 
     // get context
-    HTMLAttrContext *pCntxt = PopContext( HtmlTokenId::TEXTAREA_ON );
-    if( pCntxt )
+    std::unique_ptr<HTMLAttrContext> xCntxt(PopContext(HtmlTokenId::TEXTAREA_ON));
+    if (xCntxt)
     {
         // end attributes
-        EndContext( pCntxt );
-        delete pCntxt;
+        EndContext(xCntxt.get());
     }
 
     m_bTextArea = false;
@@ -2337,11 +2336,11 @@ void SwHTMLParser::NewSelect()
         SetControlSize( xShape, aTextSz, bMinWidth, bMinHeight );
 
     // create new context
-    HTMLAttrContext *pCntxt = new HTMLAttrContext( HtmlTokenId::SELECT_ON );
+    std::unique_ptr<HTMLAttrContext> xCntxt(new HTMLAttrContext(HtmlTokenId::SELECT_ON));
 
     // temporarily disable PRE/Listing/XMP
-    SplitPREListingXMP( pCntxt );
-    PushContext( pCntxt );
+    SplitPREListingXMP(xCntxt.get());
+    PushContext(xCntxt);
 
     m_bSelect = true;
 }
@@ -2412,12 +2411,11 @@ void SwHTMLParser::EndSelect()
     m_pFormImpl->ReleaseFCompPropSet();
 
     // get context
-    HTMLAttrContext *pCntxt = PopContext( HtmlTokenId::SELECT_ON );
-    if( pCntxt )
+    std::unique_ptr<HTMLAttrContext> xCntxt(PopContext(HtmlTokenId::SELECT_ON));
+    if (xCntxt)
     {
         // close attributes
-        EndContext( pCntxt );
-        delete pCntxt;
+        EndContext(xCntxt.get());
     }
 
     m_bSelect = false;
diff --git a/sw/source/filter/html/htmlgrin.cxx b/sw/source/filter/html/htmlgrin.cxx
index 12e20ccc4ec3..5a5924b0cfd4 100644
--- a/sw/source/filter/html/htmlgrin.cxx
+++ b/sw/source/filter/html/htmlgrin.cxx
@@ -1047,12 +1047,11 @@ void SwHTMLParser::InsertBodyOptions()
 void SwHTMLParser::NewAnchor()
 {
     // end previous link if there was one
-    HTMLAttrContext *pOldCntxt = PopContext( HtmlTokenId::ANCHOR_ON );
-    if( pOldCntxt )
+    std::unique_ptr<HTMLAttrContext> xOldCntxt(PopContext(HtmlTokenId::ANCHOR_ON));
+    if (xOldCntxt)
     {
         // and maybe end attributes
-        EndContext( pOldCntxt );
-        delete pOldCntxt;
+        EndContext(xOldCntxt.get());
     }
 
     SvxMacroTableDtor aMacroTable;
@@ -1168,7 +1167,7 @@ ANCHOR_SETEVENT:
     }
 
     // create a new context
-    HTMLAttrContext *pCntxt = new HTMLAttrContext( HtmlTokenId::ANCHOR_ON );
+    std::unique_ptr<HTMLAttrContext> xCntxt(new HTMLAttrContext(HtmlTokenId::ANCHOR_ON));
 
     bool bEnAnchor = false, bFootnoteAnchor = false, bFootnoteEnSymbol = false;
     OUString aFootnoteName;
@@ -1201,8 +1200,8 @@ ANCHOR_SETEVENT:
 
         if( ParseStyleOptions( aStyle, aId, aClass, aItemSet, aPropInfo, &aLang, &aDir ) )
         {
-            DoPositioning( aItemSet, aPropInfo, pCntxt );
-            InsertAttrs( aItemSet, aPropInfo, pCntxt, true );
+            DoPositioning(aItemSet, aPropInfo, xCntxt.get());
+            InsertAttrs(aItemSet, aPropInfo, xCntxt.get(), true);
         }
     }
 
@@ -1227,7 +1226,7 @@ ANCHOR_SETEVENT:
             aINetFormat.SetMacroTable( &aMacroTable );
 
         // set the default attribute
-        InsertAttr( &m_aAttrTab.pINetFormat, aINetFormat, pCntxt );
+        InsertAttr(&m_aAttrTab.pINetFormat, aINetFormat, xCntxt.get());
     }
     else if( !aName.isEmpty() )
     {
@@ -1245,7 +1244,7 @@ ANCHOR_SETEVENT:
     }
 
     // save context
-    PushContext( pCntxt );
+    PushContext(xCntxt);
 }
 
 void SwHTMLParser::EndAnchor()
diff --git a/sw/source/filter/html/htmlnumreader.cxx b/sw/source/filter/html/htmlnumreader.cxx
index fbda0537a119..377419d30ef2 100644
--- a/sw/source/filter/html/htmlnumreader.cxx
+++ b/sw/source/filter/html/htmlnumreader.cxx
@@ -250,7 +250,7 @@ void SwHTMLParser::NewNumBulList( HtmlTokenId nToken )
     }
 
     // create a new context
-    HTMLAttrContext *pCntxt = new HTMLAttrContext( nToken );
+    std::unique_ptr<HTMLAttrContext> xCntxt(new HTMLAttrContext(nToken));
 
     // Parse styles
     if( HasStyleOptions( aStyle, aId, aClass, &aLang, &aDir ) )
@@ -313,9 +313,9 @@ void SwHTMLParser::NewNumBulList( HtmlTokenId nToken )
                 bChangeNumFormat = false;
             }
 
-            DoPositioning( aItemSet, aPropInfo, pCntxt );
+            DoPositioning(aItemSet, aPropInfo, xCntxt.get());
 
-            InsertAttrs( aItemSet, aPropInfo, pCntxt );
+            InsertAttrs(aItemSet, aPropInfo, xCntxt.get());
         }
     }
 
@@ -325,10 +325,10 @@ void SwHTMLParser::NewNumBulList( HtmlTokenId nToken )
         m_xDoc->ChgNumRuleFormats( *rInfo.GetNumRule() );
     }
 
-    PushContext( pCntxt );
+    PushContext(xCntxt);
 
     // set attributes to the current template
-    SetTextCollAttrs( pCntxt );
+    SetTextCollAttrs(m_aContexts.back().get());
 }
 
 void SwHTMLParser::EndNumBulList( HtmlTokenId nToken )
@@ -355,10 +355,10 @@ void SwHTMLParser::EndNumBulList( HtmlTokenId nToken )
         AddParSpace();
 
     // get current context from stack
-    HTMLAttrContext *pCntxt = nToken != HtmlTokenId::NONE ? PopContext( getOnToken(nToken) ) : nullptr;
+    std::unique_ptr<HTMLAttrContext> xCntxt(nToken != HtmlTokenId::NONE ? PopContext(getOnToken(nToken)) : nullptr);
 
     // Don't end a list because of a token, if the context wasn't created or mustn't be ended
-    if( rInfo.GetDepth()>0 && (nToken == HtmlTokenId::NONE || pCntxt) )
+    if( rInfo.GetDepth()>0 && (nToken == HtmlTokenId::NONE || xCntxt) )
     {
         rInfo.DecDepth();
         if( !rInfo.GetDepth() )     // was that the last level?
@@ -412,10 +412,10 @@ void SwHTMLParser::EndNumBulList( HtmlTokenId nToken )
 
     // end attributes
     bool bSetAttrs = false;
-    if( pCntxt )
+    if (xCntxt)
     {
-        EndContext( pCntxt );
-        delete pCntxt;
+        EndContext(xCntxt.get());
+        xCntxt.reset();
         bSetAttrs = true;
     }
 
@@ -472,7 +472,7 @@ void SwHTMLParser::NewNumBulListItem( HtmlTokenId nToken )
 
     const bool bCountedInList = nToken != HtmlTokenId::LISTHEADER_ON;
 
-    HTMLAttrContext *pCntxt = new HTMLAttrContext( nToken );
+    std::unique_ptr<HTMLAttrContext> xCntxt(new HTMLAttrContext(nToken));
 
     OUString aNumRuleName;
     if( GetNumInfo().GetNumRule() )
@@ -535,15 +535,15 @@ void SwHTMLParser::NewNumBulListItem( HtmlTokenId nToken )
 
         if( ParseStyleOptions( aStyle, aId, aClass, aItemSet, aPropInfo, &aLang, &aDir ) )
         {
-            DoPositioning( aItemSet, aPropInfo, pCntxt );
-            InsertAttrs( aItemSet, aPropInfo, pCntxt );
+            DoPositioning(aItemSet, aPropInfo, xCntxt.get());
+            InsertAttrs(aItemSet, aPropInfo, xCntxt.get());
         }
     }
 
-    PushContext( pCntxt );
+    PushContext(xCntxt);
 
     // set the new template
-    SetTextCollAttrs( pCntxt );
+    SetTextCollAttrs(m_aContexts.back().get());
 
     // Refresh scroll bar
     ShowStatline();
@@ -556,10 +556,10 @@ void SwHTMLParser::EndNumBulListItem( HtmlTokenId nToken, bool bSetColl )
         AppendTextNode( AM_NOSPACE );
 
     // Get context to that token and pop it from stack
-    HTMLAttrContext *pCntxt = nullptr;
+    std::unique_ptr<HTMLAttrContext> xCntxt;
     auto nPos = m_aContexts.size();
     nToken = getOnToken(nToken);
-    while( !pCntxt && nPos>m_nContextStMin )
+    while (!xCntxt && nPos>m_nContextStMin)
     {
         HtmlTokenId nCntxtToken = m_aContexts[--nPos]->GetToken();
         switch( nCntxtToken )
@@ -568,7 +568,7 @@ void SwHTMLParser::EndNumBulListItem( HtmlTokenId nToken, bool bSetColl )
         case HtmlTokenId::LISTHEADER_ON:
             if( nToken == HtmlTokenId::NONE || nToken == nCntxtToken  )
             {
-                pCntxt = m_aContexts[nPos];
+                xCntxt = std::move(m_aContexts[nPos]);
                 m_aContexts.erase( m_aContexts.begin() + nPos );
             }
             break;
@@ -584,11 +584,11 @@ void SwHTMLParser::EndNumBulListItem( HtmlTokenId nToken, bool bSetColl )
     }
 
     // end attributes
-    if( pCntxt )
+    if (xCntxt)
     {
-        EndContext( pCntxt );
+        EndContext(xCntxt.get());
         SetAttr();  // set paragraph attributes asap because of Javascript
-        delete pCntxt;
+        xCntxt.reset();
     }
 
     // set current template
diff --git a/sw/source/filter/html/htmlsect.cxx b/sw/source/filter/html/htmlsect.cxx
index 436508a5e377..a158212e09d8 100644
--- a/sw/source/filter/html/htmlsect.cxx
+++ b/sw/source/filter/html/htmlsect.cxx
@@ -113,7 +113,7 @@ void SwHTMLParser::NewDivision( HtmlTokenId nToken )
         bAppended = true;
     }
 
-    HTMLAttrContext *pCntxt = new HTMLAttrContext( nToken );
+    std::unique_ptr<HTMLAttrContext> xCntxt(new HTMLAttrContext(nToken));
 
     bool bStyleParsed = false, bPositioned = false;
     SfxItemSet aItemSet( m_xDoc->GetAttrPool(), m_pCSS1Parser->GetWhichMap() );
@@ -126,15 +126,15 @@ void SwHTMLParser::NewDivision( HtmlTokenId nToken )
         {
             if ( aPropInfo.m_nColumnCount >= 2 )
             {
-                delete pCntxt;
+                xCntxt.reset();
                 NewMultiCol( aPropInfo.m_nColumnCount );
                 return;
             }
             bPositioned = HtmlTokenId::DIVISION_ON == nToken && !aClass.isEmpty() &&
-                          CreateContainer( aClass, aItemSet, aPropInfo,
-                                           pCntxt );
+                          CreateContainer(aClass, aItemSet, aPropInfo,
+                                          xCntxt.get());
             if( !bPositioned )
-                bPositioned = DoPositioning( aItemSet, aPropInfo, pCntxt );
+                bPositioned = DoPositioning(aItemSet, aPropInfo, xCntxt.get());
         }
     }
 
@@ -209,7 +209,7 @@ void SwHTMLParser::NewDivision( HtmlTokenId nToken )
         }
 
         SwPosition aNewPos( SwNodeIndex( rContentStIdx, 1 ), SwIndex( pCNd, 0 ) );
-        SaveDocContext( pCntxt, nFlags, &aNewPos );
+        SaveDocContext(xCntxt.get(), nFlags, &aNewPos);
     }
     else if( !bPositioned && aId.getLength() > 9 &&
              (aId[0] == 's' || aId[0] == 'S' ) &&
@@ -229,7 +229,7 @@ void SwHTMLParser::NewDivision( HtmlTokenId nToken )
                     m_xDoc->GetNodes()[pStartNdIdx->GetIndex()+1]->GetContentNode();
                 SwNodeIndex aTmpSwNodeIndex = SwNodeIndex(*pCNd);
                 SwPosition aNewPos( aTmpSwNodeIndex, SwIndex( pCNd, 0 ) );
-                SaveDocContext( pCntxt, HtmlContextFlags::MultiColMask, &aNewPos );
+                SaveDocContext(xCntxt.get(), HtmlContextFlags::MultiColMask, &aNewPos);
                 aId.clear();
                 aPropInfo.m_aId.clear();
             }
@@ -355,7 +355,7 @@ void SwHTMLParser::NewDivision( HtmlTokenId nToken )
             pPostIts = nullptr;
         }
 
-        pCntxt->SetSpansSection( true );
+        xCntxt->SetSpansSection( true );
 
         // don't insert Bookmarks with same name as sections
         if( !aPropInfo.m_aId.isEmpty() && aPropInfo.m_aId==aName )
@@ -363,47 +363,45 @@ void SwHTMLParser::NewDivision( HtmlTokenId nToken )
     }
     else
     {
-        pCntxt->SetAppendMode( AM_NOSPACE );
+        xCntxt->SetAppendMode( AM_NOSPACE );
     }
 
     if( SvxAdjust::End != eAdjust )
     {
-        InsertAttr( &m_aAttrTab.pAdjust, SvxAdjustItem(eAdjust, RES_PARATR_ADJUST), pCntxt );
+        InsertAttr(&m_aAttrTab.pAdjust, SvxAdjustItem(eAdjust, RES_PARATR_ADJUST), xCntxt.get());
     }
 
     // parse style
     if( bStyleParsed )
-        InsertAttrs( aItemSet, aPropInfo, pCntxt, true );
+        InsertAttrs( aItemSet, aPropInfo, xCntxt.get(), true );
 
-    PushContext( pCntxt );
+    PushContext(xCntxt);
 }
 
 void SwHTMLParser::EndDivision()
 {
     // search for the stack entry of the token (because we still have the div stack
     // we don't make a difference between DIV and CENTER)
-    HTMLAttrContext *pCntxt = nullptr;
+    std::unique_ptr<HTMLAttrContext> xCntxt;
     auto nPos = m_aContexts.size();
-    while( !pCntxt && nPos>m_nContextStMin )
+    while (!xCntxt && nPos>m_nContextStMin)
     {
         switch( m_aContexts[--nPos]->GetToken() )
         {
         case HtmlTokenId::CENTER_ON:
         case HtmlTokenId::DIVISION_ON:
-            pCntxt = m_aContexts[nPos];
+            xCntxt = std::move(m_aContexts[nPos]);
             m_aContexts.erase( m_aContexts.begin() + nPos );
             break;
         default: break;
         }
     }
 
-    if( pCntxt )
+    if (xCntxt)
     {
         // close attribute
-        EndContext( pCntxt );
+        EndContext(xCntxt.get());
         SetAttr();  // set paragraph attributes really fast because of JavaScript
-
-        delete pCntxt;
     }
 }
 
@@ -521,7 +519,7 @@ bool SwHTMLParser::EndSections( bool bLFStripped )
     auto nPos = m_aContexts.size();
     while( nPos>m_nContextStMin )
     {
-        HTMLAttrContext *pCntxt = m_aContexts[--nPos];
+        HTMLAttrContext *pCntxt = m_aContexts[--nPos].get();
         if( pCntxt->GetSpansSection() && EndSection( bLFStripped ) )
         {
             bSectionClosed = true;
@@ -578,7 +576,7 @@ void SwHTMLParser::NewMultiCol( sal_uInt16 columnsFromCss )
         }
     }
 
-    HTMLAttrContext *pCntxt = new HTMLAttrContext( HtmlTokenId::MULTICOL_ON );
+    std::unique_ptr<HTMLAttrContext> xCntxt(new HTMLAttrContext(HtmlTokenId::MULTICOL_ON));
 
     //.is the multicol element contained in a container? That may be the
     // case for 5.0 documents.
@@ -642,9 +640,9 @@ void SwHTMLParser::NewMultiCol( sal_uInt16 columnsFromCss )
             aPropInfo.m_aId.clear();
         }
 
-        InsertFlyFrame(aFrameItemSet, pCntxt, aFlyName);
+        InsertFlyFrame(aFrameItemSet, xCntxt.get(), aFlyName);
 
-        pCntxt->SetPopStack( true );
+        xCntxt->SetPopStack( true );
         bPositioned = true;
     }
 
@@ -742,7 +740,7 @@ void SwHTMLParser::NewMultiCol( sal_uInt16 columnsFromCss )
             pPostIts = nullptr;
         }
 
-        pCntxt->SetSpansSection( true );
+        xCntxt->SetSpansSection( true );
 
         // Insert a bookmark if its name differs from the section's name only.
         if( !aPropInfo.m_aId.isEmpty() && aPropInfo.m_aId==aName )
@@ -751,9 +749,9 @@ void SwHTMLParser::NewMultiCol( sal_uInt16 columnsFromCss )
 
     // Additional attributes must be set as hard ones.
     if( bStyleParsed )
-        InsertAttrs( aItemSet, aPropInfo, pCntxt, true );
+        InsertAttrs( aItemSet, aPropInfo, xCntxt.get(), true );
 
-    PushContext( pCntxt );
+    PushContext(xCntxt);
 }
 
 void SwHTMLParser::InsertFlyFrame( const SfxItemSet& rItemSet,
diff --git a/sw/source/filter/html/htmltab.cxx b/sw/source/filter/html/htmltab.cxx
index 16e3d7ec6c1d..4b4569117e50 100644
--- a/sw/source/filter/html/htmltab.cxx
+++ b/sw/source/filter/html/htmltab.cxx
@@ -3097,10 +3097,10 @@ CellSaveStruct::CellSaveStruct( SwHTMLParser& rParser, HTMLTable const *pCurTabl
         nToken = HtmlTokenId::TABLEDATA_ON;
         nColl = RES_POOLCOLL_TABLE;
     }
-    HTMLAttrContext *pCntxt = new HTMLAttrContext( nToken, nColl, aEmptyOUStr, true );
+    std::unique_ptr<HTMLAttrContext> xCntxt(new HTMLAttrContext(nToken, nColl, aEmptyOUStr, true));
     if( SvxAdjust::End != m_eAdjust )
-        rParser.InsertAttr( &rParser.m_aAttrTab.pAdjust, SvxAdjustItem(m_eAdjust, RES_PARATR_ADJUST),
-                            pCntxt );
+        rParser.InsertAttr(&rParser.m_aAttrTab.pAdjust, SvxAdjustItem(m_eAdjust, RES_PARATR_ADJUST),
+                           xCntxt.get());
 
     if( SwHTMLParser::HasStyleOptions( m_aStyle, m_aId, m_aClass, &m_aLang, &m_aDir ) )
     {
@@ -3117,13 +3117,13 @@ CellSaveStruct::CellSaveStruct( SwHTMLParser& rParser, HTMLTable const *pCurTabl
                 m_xBoxItem.reset(dynamic_cast<SvxBoxItem *>(pItem->Clone()));
                 aItemSet.ClearItem(RES_BOX);
             }
-            rParser.InsertAttrs( aItemSet, aPropInfo, pCntxt );
+            rParser.InsertAttrs(aItemSet, aPropInfo, xCntxt.get());
         }
     }
 
-    rParser.SplitPREListingXMP( pCntxt );
+    rParser.SplitPREListingXMP(xCntxt.get());
 
-    rParser.PushContext( pCntxt );
+    rParser.PushContext(xCntxt);
 }
 
 void CellSaveStruct::AddContents( HTMLTableCnts *pNewCnts )
@@ -3925,9 +3925,8 @@ void SwHTMLParser::BuildTableCell( HTMLTable *pCurTable, bool bReadOptions,
         // have been modified. Since it's gonna be restored by EndContext, it's okay
         while( m_aContexts.size() > m_nContextStAttrMin+1 )
         {
-            HTMLAttrContext *pCntxt = PopContext();
-            EndContext( pCntxt );
-            delete pCntxt;
+            std::unique_ptr<HTMLAttrContext> xCntxt(PopContext());
+            EndContext(xCntxt.get());
         }
 
         // Remove LFs at the paragraph end
@@ -3935,18 +3934,16 @@ void SwHTMLParser::BuildTableCell( HTMLTable *pCurTable, bool bReadOptions,
             StripTrailingPara();
 
         // If there was an adjustment set for the cell, we need to close it
-        HTMLAttrContext *pCntxt = PopContext();
-        EndContext( pCntxt );
-        delete pCntxt;
+        std::unique_ptr<HTMLAttrContext> xCntxt(PopContext());
+        EndContext(xCntxt.get());
     }
     else
     {
         // Close all still open contexts
         while( m_aContexts.size() > m_nContextStAttrMin )
         {
-            HTMLAttrContext *pCntxt = PopContext();
-            ClearContext( pCntxt );
-            delete pCntxt;
+            std::unique_ptr<HTMLAttrContext> xCntxt(PopContext());
+            ClearContext(xCntxt.get());
         }
     }
 
@@ -4635,15 +4632,15 @@ void SwHTMLParser::BuildTableCaption( HTMLTable *pCurTable )
         else
             pStNd = InsertTableSection( RES_POOLCOLL_TEXT );
 
-        HTMLAttrContext *pCntxt = new HTMLAttrContext( HtmlTokenId::CAPTION_ON );
+        std::unique_ptr<HTMLAttrContext> xCntxt(new HTMLAttrContext(HtmlTokenId::CAPTION_ON));
 
         // Table headers are always centered
         NewAttr( &m_aAttrTab.pAdjust, SvxAdjustItem(SvxAdjust::Center, RES_PARATR_ADJUST) );
 
-        HTMLAttrs &rAttrs = pCntxt->GetAttrs();
+        HTMLAttrs &rAttrs = xCntxt->GetAttrs();
         rAttrs.push_back( m_aAttrTab.pAdjust );
 
-        PushContext( pCntxt );
+        PushContext(xCntxt);
 
         // Remember the start node of the section at the table
         pCurTable->SetCaption( pStNd, bTop );
@@ -4727,9 +4724,8 @@ void SwHTMLParser::BuildTableCaption( HTMLTable *pCurTable )
     // end all still open contexts
     while( m_aContexts.size() > m_nContextStAttrMin+1 )
     {
-        HTMLAttrContext *pCntxt = PopContext();
-        EndContext( pCntxt );
-        delete pCntxt;
+        std::unique_ptr<HTMLAttrContext> xCntxt(PopContext());
+        EndContext(xCntxt.get());
     }
 
     bool bLFStripped = StripTrailingLF() > 0;
@@ -4749,9 +4745,9 @@ void SwHTMLParser::BuildTableCaption( HTMLTable *pCurTable )
     }
 
     // If there's an adjustment for the cell, we need to close it
-    HTMLAttrContext *pCntxt = PopContext();
-    EndContext( pCntxt );
-    delete pCntxt;
+    std::unique_ptr<HTMLAttrContext> xCntxt(PopContext());
+    EndContext(xCntxt.get());
+    xCntxt.reset();
 
     SetAttr( false );
 
@@ -5103,9 +5099,8 @@ std::shared_ptr<HTMLTable> SwHTMLParser::BuildTable(SvxAdjust eParentAdjust,
         // since the current one doesn't exist anymore afterwards
         while( m_aContexts.size() > m_nContextStAttrMin )
         {
-            HTMLAttrContext *pCntxt = PopContext();
-            ClearContext( pCntxt );
-            delete pCntxt;
+            std::unique_ptr<HTMLAttrContext> xCntxt(PopContext());
+            ClearContext(xCntxt.get());
         }
 
         m_nContextStMin = pTCntxt->GetContextStMin();
diff --git a/sw/source/filter/html/swhtml.cxx b/sw/source/filter/html/swhtml.cxx
index 062366ea7188..5c2ce5047d0f 100644
--- a/sw/source/filter/html/swhtml.cxx
+++ b/sw/source/filter/html/swhtml.cxx
@@ -656,11 +656,10 @@ void SwHTMLParser::Continue( HtmlTokenId nToken )
             m_nContextStMin = 0;
             while( m_aContexts.size() )
             {
-                HTMLAttrContext *pCntxt = PopContext();
-                if( pCntxt )
+                std::unique_ptr<HTMLAttrContext> xCntxt(PopContext());
+                if (xCntxt)
                 {
-                    EndContext( pCntxt );
-                    delete pCntxt;
+                    EndContext(xCntxt.get());
                 }
             }
 
@@ -3405,7 +3404,7 @@ void SwHTMLParser::NewStdAttr( HtmlTokenId nToken )
     }
 
     // create a new context
-    HTMLAttrContext *pCntxt = new HTMLAttrContext( nToken );
+    std::unique_ptr<HTMLAttrContext> xCntxt(new HTMLAttrContext(nToken));
 
     // parse styles
     if( HasStyleOptions( aStyle, aId, aClass, &aLang, &aDir ) )
@@ -3416,14 +3415,14 @@ void SwHTMLParser::NewStdAttr( HtmlTokenId nToken )
         if( ParseStyleOptions( aStyle, aId, aClass, aItemSet, aPropInfo, &aLang, &aDir ) )
         {
             if( HtmlTokenId::SPAN_ON != nToken || aClass.isEmpty() ||
-                !CreateContainer( aClass, aItemSet, aPropInfo, pCntxt ) )
-                DoPositioning( aItemSet, aPropInfo, pCntxt );
-            InsertAttrs( aItemSet, aPropInfo, pCntxt, true );
+                !CreateContainer( aClass, aItemSet, aPropInfo, xCntxt.get() ) )
+                DoPositioning( aItemSet, aPropInfo, xCntxt.get() );
+            InsertAttrs( aItemSet, aPropInfo, xCntxt.get(), true );
         }
     }
 
     // save the context
-    PushContext( pCntxt );
+    PushContext(xCntxt);
 }
 
 void SwHTMLParser::NewStdAttr( HtmlTokenId nToken,
@@ -3459,7 +3458,7 @@ void SwHTMLParser::NewStdAttr( HtmlTokenId nToken,
     }
 
     // create a new context
-    HTMLAttrContext *pCntxt = new HTMLAttrContext( nToken );
+    std::unique_ptr<HTMLAttrContext> xCntxt(new HTMLAttrContext(nToken));
 
     // parse styles
     if( HasStyleOptions( aStyle, aId, aClass, &aLang, &aDir ) )
@@ -3474,38 +3473,37 @@ void SwHTMLParser::NewStdAttr( HtmlTokenId nToken,
             aItemSet.Put( *pItem3 );
 
         if( ParseStyleOptions( aStyle, aId, aClass, aItemSet, aPropInfo, &aLang, &aDir ) )
-            DoPositioning( aItemSet, aPropInfo, pCntxt );
+            DoPositioning( aItemSet, aPropInfo, xCntxt.get() );
 
-        InsertAttrs( aItemSet, aPropInfo, pCntxt, true );
+        InsertAttrs( aItemSet, aPropInfo, xCntxt.get(), true );
     }
     else
     {
-        InsertAttr( ppAttr ,rItem, pCntxt );
+        InsertAttr( ppAttr ,rItem, xCntxt.get() );
         if( pItem2 )
         {
             OSL_ENSURE( ppAttr2, "missing table entry for item2" );
-            InsertAttr( ppAttr2, *pItem2, pCntxt );
+            InsertAttr( ppAttr2, *pItem2, xCntxt.get() );
         }
         if( pItem3 )
         {
             OSL_ENSURE( ppAttr3, "missing table entry for item3" );
-            InsertAttr( ppAttr3, *pItem3, pCntxt );
+            InsertAttr( ppAttr3, *pItem3, xCntxt.get() );
         }
     }
 
     // save the context
-    PushContext( pCntxt );
+    PushContext(xCntxt);
 }
 
 void SwHTMLParser::EndTag( HtmlTokenId nToken )
 {
     // fetch context
-    HTMLAttrContext *pCntxt = PopContext( getOnToken(nToken) );
-    if( pCntxt )
+    std::unique_ptr<HTMLAttrContext> xCntxt(PopContext(getOnToken(nToken)));
+    if (xCntxt)
     {
         // and maybe end the attributes
-        EndContext( pCntxt );
-        delete pCntxt;
+        EndContext(xCntxt.get());
     }
 }
 
@@ -3549,7 +3547,7 @@ void SwHTMLParser::NewBasefontAttr()
         nSize = 7;
 
     // create a new context
-    HTMLAttrContext *pCntxt = new HTMLAttrContext( HtmlTokenId::BASEFONT_ON );
+    std::unique_ptr<HTMLAttrContext> xCntxt(new HTMLAttrContext(HtmlTokenId::BASEFONT_ON));
 
     // parse styles
     if( HasStyleOptions( aStyle, aId, aClass, &aLang, &aDir ) )
@@ -3569,22 +3567,22 @@ void SwHTMLParser::NewBasefontAttr()
         aItemSet.Put( aFontHeightCTL );
 
         if( ParseStyleOptions( aStyle, aId, aClass, aItemSet, aPropInfo, &aLang, &aDir ) )
-            DoPositioning( aItemSet, aPropInfo, pCntxt );
+            DoPositioning( aItemSet, aPropInfo, xCntxt.get() );
 
-        InsertAttrs( aItemSet, aPropInfo, pCntxt, true );
+        InsertAttrs( aItemSet, aPropInfo, xCntxt.get(), true );
     }
     else
     {
         SvxFontHeightItem aFontHeight( m_aFontHeights[nSize-1], 100, RES_CHRATR_FONTSIZE );
-        InsertAttr( &m_aAttrTab.pFontHeight, aFontHeight, pCntxt );
+        InsertAttr( &m_aAttrTab.pFontHeight, aFontHeight, xCntxt.get() );
         SvxFontHeightItem aFontHeightCJK( m_aFontHeights[nSize-1], 100, RES_CHRATR_CJK_FONTSIZE );
-        InsertAttr( &m_aAttrTab.pFontHeightCJK, aFontHeightCJK, pCntxt );
+        InsertAttr( &m_aAttrTab.pFontHeightCJK, aFontHeightCJK, xCntxt.get() );
         SvxFontHeightItem aFontHeightCTL( m_aFontHeights[nSize-1], 100, RES_CHRATR_CTL_FONTSIZE );
-        InsertAttr( &m_aAttrTab.pFontHeightCTL, aFontHeightCTL, pCntxt );
+        InsertAttr( &m_aAttrTab.pFontHeightCTL, aFontHeightCTL, xCntxt.get() );
     }
 
     // save the context
-    PushContext( pCntxt );
+    PushContext(xCntxt);
 
     // save the font size
     m_aBaseFontStack.push_back( nSize );
@@ -3753,7 +3751,7 @@ void SwHTMLParser::NewFontAttr( HtmlTokenId nToken )
     }
 
     // create a new context
-    HTMLAttrContext *pCntxt = new HTMLAttrContext(nToken );
+    std::unique_ptr<HTMLAttrContext> xCntxt(new HTMLAttrContext(nToken));
 
     // parse styles
     if( HasStyleOptions( aStyle, aId, aClass, &aLang, &aDir ) )
@@ -3783,36 +3781,36 @@ void SwHTMLParser::NewFontAttr( HtmlTokenId nToken )
         }
 
         if( ParseStyleOptions( aStyle, aId, aClass, aItemSet, aPropInfo, &aLang, &aDir ) )
-            DoPositioning( aItemSet, aPropInfo, pCntxt );
+            DoPositioning( aItemSet, aPropInfo, xCntxt.get() );
 
-        InsertAttrs( aItemSet, aPropInfo, pCntxt, true );
+        InsertAttrs( aItemSet, aPropInfo, xCntxt.get(), true );
     }
     else
     {
         if( nFontHeight )
         {
             SvxFontHeightItem aFontHeight( nFontHeight, 100, RES_CHRATR_FONTSIZE );
-            InsertAttr( &m_aAttrTab.pFontHeight, aFontHeight, pCntxt );
+            InsertAttr( &m_aAttrTab.pFontHeight, aFontHeight, xCntxt.get() );
             SvxFontHeightItem aFontHeightCJK( nFontHeight, 100, RES_CHRATR_CJK_FONTSIZE );
-            InsertAttr( &m_aAttrTab.pFontHeight, aFontHeightCJK, pCntxt );
+            InsertAttr( &m_aAttrTab.pFontHeight, aFontHeightCJK, xCntxt.get() );
             SvxFontHeightItem aFontHeightCTL( nFontHeight, 100, RES_CHRATR_CTL_FONTSIZE );
-            InsertAttr( &m_aAttrTab.pFontHeight, aFontHeightCTL, pCntxt );
+            InsertAttr( &m_aAttrTab.pFontHeight, aFontHeightCTL, xCntxt.get() );
         }
         if( bColor )
-            InsertAttr( &m_aAttrTab.pFontColor, SvxColorItem(aColor, RES_CHRATR_COLOR), pCntxt );
+            InsertAttr( &m_aAttrTab.pFontColor, SvxColorItem(aColor, RES_CHRATR_COLOR), xCntxt.get() );
         if( !aFontName.isEmpty() )
         {
             SvxFontItem aFont( eFamily, aFontName, aStyleName, ePitch, eEnc, RES_CHRATR_FONT );
-            InsertAttr( &m_aAttrTab.pFont, aFont, pCntxt );
+            InsertAttr( &m_aAttrTab.pFont, aFont, xCntxt.get() );
             SvxFontItem aFontCJK( eFamily, aFontName, aStyleName, ePitch, eEnc, RES_CHRATR_CJK_FONT );
-            InsertAttr( &m_aAttrTab.pFont, aFontCJK, pCntxt );
+            InsertAttr( &m_aAttrTab.pFont, aFontCJK, xCntxt.get() );
             SvxFontItem aFontCTL( eFamily, aFontName, aStyleName, ePitch, eEnc, RES_CHRATR_CTL_FONT );
-            InsertAttr( &m_aAttrTab.pFont, aFontCTL, pCntxt );
+            InsertAttr( &m_aAttrTab.pFont, aFontCTL, xCntxt.get() );
         }
     }
 
     // save the context
-    PushContext( pCntxt );
+    PushContext(xCntxt);
 
     m_aFontStack.push_back( nSize );
 }
@@ -3865,10 +3863,10 @@ void SwHTMLParser::NewPara()
     }
 
     // create a new context
-    HTMLAttrContext *pCntxt =
+    std::unique_ptr<HTMLAttrContext> xCntxt(
         !aClass.isEmpty() ? new HTMLAttrContext( HtmlTokenId::PARABREAK_ON,
                                              RES_POOLCOLL_TEXT, aClass )
-                     : new HTMLAttrContext( HtmlTokenId::PARABREAK_ON );
+                     : new HTMLAttrContext( HtmlTokenId::PARABREAK_ON ));
 
     // parse styles (Don't consider class. This is only possible as long as none of
     // the CSS1 properties of the class must be formatted hard!!!)
@@ -3881,19 +3879,19 @@ void SwHTMLParser::NewPara()
         {
             OSL_ENSURE( aClass.isEmpty() || !m_pCSS1Parser->GetClass( aClass ),
                     "Class is not considered" );
-            DoPositioning( aItemSet, aPropInfo, pCntxt );
-            InsertAttrs( aItemSet, aPropInfo, pCntxt );
+            DoPositioning( aItemSet, aPropInfo, xCntxt.get() );
+            InsertAttrs( aItemSet, aPropInfo, xCntxt.get() );
         }
     }
 
     if( SvxAdjust::End != m_eParaAdjust )
-        InsertAttr( &m_aAttrTab.pAdjust, SvxAdjustItem(m_eParaAdjust, RES_PARATR_ADJUST), pCntxt );
+        InsertAttr( &m_aAttrTab.pAdjust, SvxAdjustItem(m_eParaAdjust, RES_PARATR_ADJUST), xCntxt.get() );
 
     // and push on stack
-    PushContext( pCntxt );
+    PushContext( xCntxt );
 
     // set the current style or its attributes
-    SetTextCollAttrs( !aClass.isEmpty() ? pCntxt : nullptr );
+    SetTextCollAttrs( !aClass.isEmpty() ? m_aContexts.back().get() : nullptr );
 
     // progress bar
     ShowStatline();
@@ -3931,15 +3929,15 @@ void SwHTMLParser::EndPara( bool bReal )
 
     // Pop the context of the stack. It can also be from an
     // implied opened definition list.
-    HTMLAttrContext *pCntxt =
-        PopContext( m_nOpenParaToken != HtmlTokenId::NONE ? getOnToken(m_nOpenParaToken) : HtmlTokenId::PARABREAK_ON );
+    std::unique_ptr<HTMLAttrContext> xCntxt(
+        PopContext( m_nOpenParaToken != HtmlTokenId::NONE ? getOnToken(m_nOpenParaToken) : HtmlTokenId::PARABREAK_ON ));
 
     // close attribute
-    if( pCntxt )
+    if (xCntxt)
     {
-        EndContext( pCntxt );
+        EndContext(xCntxt.get());
         SetAttr();  // because of JavaScript set paragraph attributes as fast as possible
-        delete pCntxt;
+        xCntxt.reset();
     }
 
     // reset the existing style
@@ -4003,7 +4001,7 @@ void SwHTMLParser::NewHeading( HtmlTokenId nToken )
     }
 
     // create the context
-    HTMLAttrContext *pCntxt = new HTMLAttrContext( nToken, nTextColl, aClass );
+    std::unique_ptr<HTMLAttrContext> xCntxt(new HTMLAttrContext(nToken, nTextColl, aClass));
 
     // parse styles (regarding class see also NewPara)
     if( HasStyleOptions( aStyle, aId, aEmptyOUStr, &aLang, &aDir ) )
@@ -4015,19 +4013,19 @@ void SwHTMLParser::NewHeading( HtmlTokenId nToken )
         {
             OSL_ENSURE( aClass.isEmpty() || !m_pCSS1Parser->GetClass( aClass ),
                     "Class is not considered" );
-            DoPositioning( aItemSet, aPropInfo, pCntxt );
-            InsertAttrs( aItemSet, aPropInfo, pCntxt );
+            DoPositioning( aItemSet, aPropInfo, xCntxt.get() );
+            InsertAttrs( aItemSet, aPropInfo, xCntxt.get() );
         }
     }
 
     if( SvxAdjust::End != m_eParaAdjust )
-        InsertAttr( &m_aAttrTab.pAdjust, SvxAdjustItem(m_eParaAdjust, RES_PARATR_ADJUST), pCntxt );
+        InsertAttr( &m_aAttrTab.pAdjust, SvxAdjustItem(m_eParaAdjust, RES_PARATR_ADJUST), xCntxt.get() );
 
     // and push on stack
-    PushContext( pCntxt );
+    PushContext(xCntxt);
 
     // set the current style or its attributes
-    SetTextCollAttrs( pCntxt );
+    SetTextCollAttrs(m_aContexts.back().get());
 
     m_nFontStHeadStart = m_aFontStack.size();
 
@@ -4044,9 +4042,9 @@ void SwHTMLParser::EndHeading()
         AddParSpace();
 
     // search context matching the token and fetch it from stack
-    HTMLAttrContext *pCntxt = nullptr;
+    std::unique_ptr<HTMLAttrContext> xCntxt;
     auto nPos = m_aContexts.size();
-    while( !pCntxt && nPos>m_nContextStMin )
+    while( !xCntxt && nPos>m_nContextStMin )
     {
         switch( m_aContexts[--nPos]->GetToken() )
         {
@@ -4056,7 +4054,7 @@ void SwHTMLParser::EndHeading()
         case HtmlTokenId::HEAD4_ON:
         case HtmlTokenId::HEAD5_ON:
         case HtmlTokenId::HEAD6_ON:
-            pCntxt = m_aContexts[nPos];
+            xCntxt = std::move(m_aContexts[nPos]);
             m_aContexts.erase( m_aContexts.begin() + nPos );
             break;
         default: break;
@@ -4064,11 +4062,11 @@ void SwHTMLParser::EndHeading()
     }
 
     // and now end attributes
-    if( pCntxt )
+    if (xCntxt)
     {
-        EndContext( pCntxt );
+        EndContext(xCntxt.get());
         SetAttr();  // because of JavaScript set paragraph attributes as fast as possible
-        delete pCntxt;
+        xCntxt.reset();
     }
 
     // reset existing style
@@ -4139,7 +4137,7 @@ void SwHTMLParser::NewTextFormatColl( HtmlTokenId nToken, sal_uInt16 nColl )
         AddParSpace();
 
     // ... and save in a context
-    HTMLAttrContext *pCntxt = new HTMLAttrContext( nToken, nColl, aClass );
+    std::unique_ptr<HTMLAttrContext> xCntxt(new HTMLAttrContext(nToken, nColl, aClass));
 
     // parse styles (regarding class see also NewPara)
     if( HasStyleOptions( aStyle, aId, aEmptyOUStr, &aLang, &aDir ) )
@@ -4151,15 +4149,15 @@ void SwHTMLParser::NewTextFormatColl( HtmlTokenId nToken, sal_uInt16 nColl )
         {
             OSL_ENSURE( aClass.isEmpty() || !m_pCSS1Parser->GetClass( aClass ),
                     "Class is not considered" );
-            DoPositioning( aItemSet, aPropInfo, pCntxt );
-            InsertAttrs( aItemSet, aPropInfo, pCntxt );
+            DoPositioning( aItemSet, aPropInfo, xCntxt.get() );
+            InsertAttrs( aItemSet, aPropInfo, xCntxt.get() );
         }
     }
 
-    PushContext( pCntxt );
+    PushContext(xCntxt);
 
     // set the new style
-    SetTextCollAttrs( pCntxt );
+    SetTextCollAttrs(m_aContexts.back().get());
 
     // update progress bar
     ShowStatline();
@@ -4192,14 +4190,14 @@ void SwHTMLParser::EndTextFormatColl( HtmlTokenId nToken )
         AddParSpace();
 
     // pop current context of stack
-    HTMLAttrContext *pCntxt = PopContext( getOnToken(nToken) );
+    std::unique_ptr<HTMLAttrContext> xCntxt(PopContext(getOnToken(nToken)));
 
     // and now end attributes
-    if( pCntxt )
+    if (xCntxt)
     {
-        EndContext( pCntxt );
+        EndContext(xCntxt.get());
         SetAttr();  // because of JavaScript set paragraph attributes as fast as possible
-        delete pCntxt;
+        xCntxt.reset();
     }
 
     // reset existing style
@@ -4267,7 +4265,7 @@ void SwHTMLParser::NewDefList()
     }
 
     // ... and save in a context
-    HTMLAttrContext *pCntxt = new HTMLAttrContext( HtmlTokenId::DEFLIST_ON );
+    std::unique_ptr<HTMLAttrContext> xCntxt(new HTMLAttrContext(HtmlTokenId::DEFLIST_ON));
 
     // in it save also the margins
     sal_uInt16 nLeft=0, nRight=0;
@@ -4287,7 +4285,7 @@ void SwHTMLParser::NewDefList()
         nLeft = nLeft + static_cast< sal_uInt16 >(rLRSpace.GetTextLeft());
     }
 
-    pCntxt->SetMargins( nLeft, nRight, nIndent );
+    xCntxt->SetMargins( nLeft, nRight, nIndent );
 
     // parse styles
     if( HasStyleOptions( aStyle, aId, aClass, &aLang, &aDir ) )
@@ -4297,16 +4295,16 @@ void SwHTMLParser::NewDefList()
 
         if( ParseStyleOptions( aStyle, aId, aClass, aItemSet, aPropInfo, &aLang, &aDir ) )
         {
-            DoPositioning( aItemSet, aPropInfo, pCntxt );
-            InsertAttrs( aItemSet, aPropInfo, pCntxt );
+            DoPositioning( aItemSet, aPropInfo, xCntxt.get() );
+            InsertAttrs( aItemSet, aPropInfo, xCntxt.get() );
         }
     }
 
-    PushContext( pCntxt );
+    PushContext(xCntxt);
 
     // set the attributes of the new style
     if( m_nDefListDeep > 1 )
-        SetTextCollAttrs( pCntxt );
+        SetTextCollAttrs(m_aContexts.back().get());
 }
 
 void SwHTMLParser::EndDefList()
@@ -4322,14 +4320,14 @@ void SwHTMLParser::EndDefList()
         m_nDefListDeep--;
 
     // pop current context of stack
-    HTMLAttrContext *pCntxt = PopContext( HtmlTokenId::DEFLIST_ON );
+    std::unique_ptr<HTMLAttrContext> xCntxt(PopContext(HtmlTokenId::DEFLIST_ON));
 
     // and now end attributes
-    if( pCntxt )
+    if (xCntxt)
     {
-        EndContext( pCntxt );
+        EndContext(xCntxt.get());
         SetAttr();  // because of JavaScript set paragraph attributes as fast as possible
-        delete pCntxt;
+        xCntxt.reset();
     }
 
     // and set style
@@ -4380,9 +4378,9 @@ void SwHTMLParser::EndDefListItem( HtmlTokenId nToken )
 
     // search context matching the token and fetch it from stack
     nToken = getOnToken(nToken);
-    HTMLAttrContext *pCntxt = nullptr;
+    std::unique_ptr<HTMLAttrContext> xCntxt;
     auto nPos = m_aContexts.size();
-    while( !pCntxt && nPos>m_nContextStMin )
+    while( !xCntxt && nPos>m_nContextStMin )
     {
         HtmlTokenId nCntxtToken = m_aContexts[--nPos]->GetToken();
         switch( nCntxtToken )
@@ -4391,7 +4389,7 @@ void SwHTMLParser::EndDefListItem( HtmlTokenId nToken )
         case HtmlTokenId::DT_ON:
             if( nToken == HtmlTokenId::NONE || nToken == nCntxtToken  )
             {
-                pCntxt = m_aContexts[nPos];
+                xCntxt = std::move(m_aContexts[nPos]);
                 m_aContexts.erase( m_aContexts.begin() + nPos );
             }
             break;
@@ -4409,11 +4407,10 @@ void SwHTMLParser::EndDefListItem( HtmlTokenId nToken )
     }
 
     // and now end attributes
-    if( pCntxt )
+    if (xCntxt)
     {
-        EndContext( pCntxt );
+        EndContext(xCntxt.get());
         SetAttr();  // because of JavaScript set paragraph attributes as fast as possible
-        delete pCntxt;
     }
 }
 
@@ -4513,7 +4510,7 @@ void SwHTMLParser::SetTextCollAttrs( HTMLAttrContext *pContext )
 
     for( auto i = m_nContextStAttrMin; i < m_aContexts.size(); ++i )
     {
-        const HTMLAttrContext *pCntxt = m_aContexts[i];
+        const HTMLAttrContext *pCntxt = m_aContexts[i].get();
 
         sal_uInt16 nColl = pCntxt->GetTextFormatColl();
         if( nColl )
@@ -4746,7 +4743,7 @@ void SwHTMLParser::NewCharFormat( HtmlTokenId nToken )
     }
 
     // create a new context
-    HTMLAttrContext *pCntxt = new HTMLAttrContext( nToken );
+    std::unique_ptr<HTMLAttrContext> xCntxt(new HTMLAttrContext(nToken));
 
     // set the style and save it in the context
     SwCharFormat* pCFormat = m_pCSS1Parser->GetChrFormat( nToken, aClass );
@@ -4762,18 +4759,18 @@ void SwHTMLParser::NewCharFormat( HtmlTokenId nToken )
         {
             OSL_ENSURE( aClass.isEmpty() || !m_pCSS1Parser->GetClass( aClass ),
                     "Class is not considered" );
-            DoPositioning( aItemSet, aPropInfo, pCntxt );
-            InsertAttrs( aItemSet, aPropInfo, pCntxt, true );
+            DoPositioning( aItemSet, aPropInfo, xCntxt.get() );
+            InsertAttrs( aItemSet, aPropInfo, xCntxt.get(), true );
         }
     }
 
     // Character formats are stored in their own stack and can never be inserted
     // by styles. Therefore the attribute doesn't exist in CSS1-Which-Range.
     if( pCFormat )
-        InsertAttr( &m_aAttrTab.pCharFormats, SwFormatCharFormat( pCFormat ), pCntxt );
+        InsertAttr( &m_aAttrTab.pCharFormats, SwFormatCharFormat( pCFormat ), xCntxt.get() );
 
     // save the context
-    PushContext( pCntxt );
+    PushContext(xCntxt);
 }
 
 void SwHTMLParser::InsertSpacer()
@@ -5216,13 +5213,13 @@ void SwHTMLParser::InsertHorzRule()
     m_pPam->Move( fnMoveBackward );
 
     // ...and save in a context
-    HTMLAttrContext *pCntxt =
-        new HTMLAttrContext( HtmlTokenId::HORZRULE, RES_POOLCOLL_HTML_HR, aEmptyOUStr );
+    std::unique_ptr<HTMLAttrContext> xCntxt(
+        new HTMLAttrContext(HtmlTokenId::HORZRULE, RES_POOLCOLL_HTML_HR, aEmptyOUStr));
 
-    PushContext( pCntxt );
+    PushContext(xCntxt);
 
     // set the new style
-    SetTextCollAttrs( pCntxt );
+    SetTextCollAttrs(m_aContexts.back().get());
 
     // the hard attributes of the current paragraph will never become invalid
     if( !m_aParaAttrs.empty() )
@@ -5309,9 +5306,8 @@ void SwHTMLParser::InsertHorzRule()
         InsertBookmark( aId );
 
     // pop current context of stack
-    HTMLAttrContext *pPoppedContext = PopContext( HtmlTokenId::HORZRULE );
-    OSL_ENSURE( pPoppedContext==pCntxt, "Where does the HR context come from?" );
-    delete pPoppedContext;
+    std::unique_ptr<HTMLAttrContext> xPoppedContext(PopContext(HtmlTokenId::HORZRULE));
+    xPoppedContext.reset();
 
     m_pPam->Move( fnMoveForward );
 
diff --git a/sw/source/filter/html/swhtml.hxx b/sw/source/filter/html/swhtml.hxx
index 8ca919895a04..799d856b4577 100644
--- a/sw/source/filter/html/swhtml.hxx
+++ b/sw/source/filter/html/swhtml.hxx
@@ -324,7 +324,7 @@ public:
     SwHTMLAppendMode GetAppendMode() const { return eAppend; }
 };
 
-typedef std::vector<HTMLAttrContext *> HTMLAttrContexts;
+typedef std::vector<std::unique_ptr<HTMLAttrContext>> HTMLAttrContexts;
 
 class HTMLTable;
 class SwCSS1Parser;
@@ -554,11 +554,14 @@ class SwHTMLParser : public SfxHTMLParser, public SwClient
     // Manage attribute context
 
     // save current context
-    inline void PushContext( HTMLAttrContext *pCntxt );
+    void PushContext(std::unique_ptr<HTMLAttrContext>& rCntxt)
+    {
+        m_aContexts.push_back(std::move(rCntxt));
+    }
 
     // Fetch top/specified context but not outside the context with token
     // nLimit. If bRemove set then remove it.
-    HTMLAttrContext *PopContext( HtmlTokenId nToken = HtmlTokenId::NONE );
+    std::unique_ptr<HTMLAttrContext> PopContext(HtmlTokenId nToken = HtmlTokenId::NONE);
 
     bool GetMarginsFromContext( sal_uInt16 &nLeft, sal_uInt16 &nRight, short& nIndent,
                                 bool bIgnoreCurrent=false ) const;
@@ -962,11 +965,6 @@ inline bool SwHTMLParser::HasStyleOptions( const OUString &rStyle,
            (pLang && !pLang->isEmpty()) || (pDir && !pDir->isEmpty());
 }
 
-inline void SwHTMLParser::PushContext( HTMLAttrContext *pCntxt )
-{
-    m_aContexts.push_back( pCntxt );
-}
-
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list