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

Ashod Nakashian ashodnakashian at yahoo.com
Tue Nov 3 02:00:16 PST 2015


 sw/source/core/layout/calcmove.cxx |   12 ++++++------
 sw/source/core/layout/flowfrm.cxx  |   24 +++++++++---------------
 sw/source/core/layout/hffrm.cxx    |   14 ++++----------
 sw/source/core/layout/tabfrm.cxx   |   25 +++++++++++++------------
 4 files changed, 32 insertions(+), 43 deletions(-)

New commits:
commit 48cc54ec2ad5ca7e17ac1f705895d373917a37cb
Author: Ashod Nakashian <ashodnakashian at yahoo.com>
Date:   Fri Oct 30 22:12:24 2015 -0400

    Smart pointers for SwBorderAttrAccess
    
    The short-lived SwBorderAttrAccess is manually deleted
    which is not exception safe and can potentially leak.
    This wraps it in unique_ptr.
    
    Change-Id: Ib45c1c36214583e0bf205231f9f793e023d106c7
    Reviewed-on: https://gerrit.libreoffice.org/19701
    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/core/layout/calcmove.cxx b/sw/source/core/layout/calcmove.cxx
index fb66080..ea5602e 100644
--- a/sw/source/core/layout/calcmove.cxx
+++ b/sw/source/core/layout/calcmove.cxx
@@ -43,6 +43,7 @@
 
 #include <DocumentSettingManager.hxx>
 #include <IDocumentLayoutAccess.hxx>
+#include <o3tl/make_unique.hxx>
 
 // Move methods
 
@@ -643,7 +644,7 @@ void SwPageFrm::MakeAll(vcl::RenderContext* pRenderContext)
 
     const SwRect aOldRect( Frm() );     // Adjust root size
     const SwLayNotify aNotify( this );  // takes care of the notification in the dtor
-    SwBorderAttrAccess *pAccess = 0;
+    std::unique_ptr<SwBorderAttrAccess> pAccess;
     const SwBorderAttrs*pAttrs = 0;
 
     while ( !mbValidPos || !mbValidSize || !mbValidPrtArea )
@@ -666,7 +667,7 @@ void SwPageFrm::MakeAll(vcl::RenderContext* pRenderContext)
             {
                 if ( !pAccess )
                 {
-                    pAccess = new SwBorderAttrAccess( SwFrm::GetCache(), this );
+                    pAccess = o3tl::make_unique<SwBorderAttrAccess>(SwFrm::GetCache(), this);
                     pAttrs = pAccess->Get();
                 }
                 // In BrowseView, we use fixed settings
@@ -772,7 +773,6 @@ void SwPageFrm::MakeAll(vcl::RenderContext* pRenderContext)
             }
         }
     } //while ( !mbValidPos || !mbValidSize || !mbValidPrtArea )
-    delete pAccess;
 
     if ( Frm() != aOldRect && GetUpper() )
         static_cast<SwRootFrm*>(GetUpper())->CheckViewLayout( 0, 0 );
@@ -791,7 +791,7 @@ void SwLayoutFrm::MakeAll(vcl::RenderContext* /*pRenderContext*/)
 
     SwRectFn fnRect = ( IsNeighbourFrm() == bVert )? fnRectHori : ( IsVertLR() ? fnRectVertL2R : fnRectVert );
 
-    SwBorderAttrAccess *pAccess = 0;
+    std::unique_ptr<SwBorderAttrAccess> pAccess;
     const SwBorderAttrs*pAttrs = 0;
 
     while ( !mbValidPos || !mbValidSize || !mbValidPrtArea )
@@ -845,17 +845,17 @@ void SwLayoutFrm::MakeAll(vcl::RenderContext* /*pRenderContext*/)
                 }
             }
         }
+
         if ( !mbValidSize || !mbValidPrtArea )
         {
             if ( !pAccess )
             {
-                pAccess = new SwBorderAttrAccess( SwFrm::GetCache(), this );
+                pAccess = o3tl::make_unique<SwBorderAttrAccess>(SwFrm::GetCache(), this);
                 pAttrs  = pAccess->Get();
             }
             Format( getRootFrm()->GetCurrShell()->GetOut(), pAttrs );
         }
     } //while ( !mbValidPos || !mbValidSize || !mbValidPrtArea )
-    delete pAccess;
 }
 
 bool SwTextNode::IsCollapse() const
diff --git a/sw/source/core/layout/flowfrm.cxx b/sw/source/core/layout/flowfrm.cxx
index c17391b..e6f224b 100644
--- a/sw/source/core/layout/flowfrm.cxx
+++ b/sw/source/core/layout/flowfrm.cxx
@@ -55,6 +55,7 @@
 #include <calbck.hxx>
 #include <IDocumentSettingAccess.hxx>
 #include <IDocumentDrawModelAccess.hxx>
+#include <o3tl/make_unique.hxx>
 
 bool SwFlowFrm::m_bMoveBwdJump = false;
 
@@ -1329,12 +1330,11 @@ static bool lcl_IdenticalStyles(const SwFrm* pPrevFrm, const SwFrm* pFrm)
 static bool lcl_getContextualSpacing(const SwFrm* pPrevFrm)
 {
     bool bRet;
-    SwBorderAttrAccess *pAccess = new SwBorderAttrAccess( SwFrm::GetCache(), pPrevFrm );
+    auto pAccess = o3tl::make_unique<SwBorderAttrAccess>(SwFrm::GetCache(), pPrevFrm);
     const SwBorderAttrs *pAttrs = pAccess->Get();
 
     bRet = pAttrs->GetULSpace().GetContext();
 
-    delete pAccess;
     return bRet;
 }
 
@@ -1346,7 +1346,7 @@ SwTwips SwFlowFrm::CalcUpperSpace( const SwBorderAttrs *pAttrs,
     // OD 2004-03-10 #i11860# - use new method <GetPrevFrmForUpperSpaceCalc(..)>
     const SwFrm* pPrevFrm = _GetPrevFrmForUpperSpaceCalc( pPr );
 
-    SwBorderAttrAccess *pAccess;
+    std::unique_ptr<SwBorderAttrAccess> pAccess;
     SwFrm* pOwn;
     if( !pAttrs )
     {
@@ -1361,12 +1361,11 @@ SwTwips SwFlowFrm::CalcUpperSpace( const SwBorderAttrs *pAttrs,
         }
         else
             pOwn = &m_rThis;
-        pAccess= new SwBorderAttrAccess( SwFrm::GetCache(), pOwn );
+        pAccess = o3tl::make_unique<SwBorderAttrAccess>(SwFrm::GetCache(), pOwn);
         pAttrs = pAccess->Get();
     }
     else
     {
-        pAccess = NULL;
         pOwn = &m_rThis;
     }
     SwTwips nUpper = 0;
@@ -1496,8 +1495,7 @@ SwTwips SwFlowFrm::CalcUpperSpace( const SwBorderAttrs *pAttrs,
         nUpper += _GetUpperSpaceAmountConsideredForPageGrid( nUpper );
     }
 
-    bool bContextualSpacing = pAttrs->GetULSpace().GetContext();
-    delete pAccess;
+    const bool bContextualSpacing = pAttrs->GetULSpace().GetContext();
 
     if (bContextualSpacing && pPrevFrm && lcl_getContextualSpacing(pPrevFrm)
             && lcl_IdenticalStyles(pPrevFrm, &m_rThis))
@@ -1628,10 +1626,10 @@ SwTwips SwFlowFrm::CalcLowerSpace( const SwBorderAttrs* _pAttrs ) const
 {
     SwTwips nLowerSpace = 0;
 
-    SwBorderAttrAccess* pAttrAccess = 0L;
+    std::unique_ptr<SwBorderAttrAccess> pAttrAccess;
     if ( !_pAttrs )
     {
-        pAttrAccess = new SwBorderAttrAccess( SwFrm::GetCache(), &m_rThis );
+        pAttrAccess = o3tl::make_unique<SwBorderAttrAccess>(SwFrm::GetCache(), &m_rThis);
         _pAttrs = pAttrAccess->Get();
     }
 
@@ -1656,8 +1654,6 @@ SwTwips SwFlowFrm::CalcLowerSpace( const SwBorderAttrs* _pAttrs ) const
         nLowerSpace += CalcAddLowerSpaceAsLastInTableCell( _pAttrs );
     }
 
-    delete pAttrAccess;
-
     return nLowerSpace;
 }
 
@@ -1688,17 +1684,15 @@ SwTwips SwFlowFrm::CalcAddLowerSpaceAsLastInTableCell(
             }
         }
 
-        SwBorderAttrAccess* pAttrAccess = NULL;
+        std::unique_ptr<SwBorderAttrAccess> pAttrAccess;
         if (pFrm && (!_pAttrs || pFrm != &m_rThis))
         {
-            pAttrAccess = new SwBorderAttrAccess( SwFrm::GetCache(), pFrm );
+            pAttrAccess = o3tl::make_unique<SwBorderAttrAccess>(SwFrm::GetCache(), pFrm);
             _pAttrs = pAttrAccess->Get();
         }
 
         if (_pAttrs)
             nAdditionalLowerSpace += _pAttrs->GetULSpace().GetLower();
-
-        delete pAttrAccess;
     }
 
     return nAdditionalLowerSpace;
diff --git a/sw/source/core/layout/hffrm.cxx b/sw/source/core/layout/hffrm.cxx
index 98fb929..626c8f3 100644
--- a/sw/source/core/layout/hffrm.cxx
+++ b/sw/source/core/layout/hffrm.cxx
@@ -31,6 +31,7 @@
 #include "hfspacingitem.hxx"
 #include <sortedobjs.hxx>
 #include <objectformatter.hxx>
+#include <o3tl/make_unique.hxx>
 
 extern bool bObjsDirect;    //frmtool.cxx
 
@@ -434,8 +435,7 @@ SwTwips SwHeadFootFrm::GrowFrm( SwTwips nDist, bool bTst, bool bInfo )
     {
         nResult = 0;
 
-        SwBorderAttrAccess * pAccess =
-            new SwBorderAttrAccess( SwFrm::GetCache(), this );
+        auto pAccess = o3tl::make_unique<SwBorderAttrAccess>(SwFrm::GetCache(), this);
         OSL_ENSURE(pAccess, "no border attributes");
 
         SwBorderAttrs * pAttrs = pAccess->Get();
@@ -451,8 +451,6 @@ SwTwips SwHeadFootFrm::GrowFrm( SwTwips nDist, bool bTst, bool bInfo )
         else
             nMaxEat = maPrt.Top() - pAttrs->CalcTopLine();
 
-        delete pAccess;
-
         if (nMaxEat < 0)
             nMaxEat = 0;
 
@@ -497,7 +495,7 @@ SwTwips SwHeadFootFrm::GrowFrm( SwTwips nDist, bool bTst, bool bInfo )
 
         if (nDist - nEat > 0)
         {
-            SwTwips nFrmGrow =
+            const SwTwips nFrmGrow =
                 SwLayoutFrm::GrowFrm( nDist - nEat, bTst, bInfo );
 
             nResult += nFrmGrow;
@@ -566,9 +564,7 @@ SwTwips SwHeadFootFrm::ShrinkFrm( SwTwips nDist, bool bTst, bool bInfo )
         bool bNotifyFlys = false;
         if (nRest > 0)
         {
-
-            SwBorderAttrAccess * pAccess =
-                new SwBorderAttrAccess( SwFrm::GetCache(), this );
+            auto pAccess = o3tl::make_unique<SwBorderAttrAccess>(SwFrm::GetCache(), this);
             OSL_ENSURE(pAccess, "no border attributes");
 
             SwBorderAttrs * pAttrs = pAccess->Get();
@@ -581,8 +577,6 @@ SwTwips SwHeadFootFrm::ShrinkFrm( SwTwips nDist, bool bTst, bool bInfo )
             if (nMinPrtHeight < 0)
                 nMinPrtHeight = 0;
 
-            delete pAccess;
-
             /* assume all shrinking can be provided */
             SwTwips nShrink = nRest;
 
diff --git a/sw/source/core/layout/tabfrm.cxx b/sw/source/core/layout/tabfrm.cxx
index 3f9a488..8378ab0 100644
--- a/sw/source/core/layout/tabfrm.cxx
+++ b/sw/source/core/layout/tabfrm.cxx
@@ -55,6 +55,7 @@
 #include <calbck.hxx>
 #include <DocumentSettingManager.hxx>
 #include <docary.hxx>
+#include <o3tl/make_unique.hxx>
 
 using namespace ::com::sun::star;
 
@@ -1760,7 +1761,7 @@ void SwTabFrm::MakeAll(vcl::RenderContext* pRenderContext)
     const bool bFootnotesInDoc = !GetFormat()->GetDoc()->GetFootnoteIdxs().empty();
     const bool bFly     = IsInFly();
 
-    SwBorderAttrAccess  *pAccess= new SwBorderAttrAccess( SwFrm::GetCache(), this );
+    auto pAccess = o3tl::make_unique<SwBorderAttrAccess>(SwFrm::GetCache(), this);
     const SwBorderAttrs *pAttrs = pAccess->Get();
 
     // The beloved keep attribute
@@ -1866,10 +1867,10 @@ void SwTabFrm::MakeAll(vcl::RenderContext* pRenderContext)
                 SwHTMLTableLayout *pLayout = GetTable()->GetHTMLTableLayout();
                 if( pLayout )
                 {
-                    delete pAccess;
+                    pAccess.reset();
                     m_bCalcLowers |= pLayout->Resize(
                         pLayout->GetBrowseWidthByTabFrm( *this ) );
-                    pAccess = new SwBorderAttrAccess( SwFrm::GetCache(), this );
+                    pAccess = o3tl::make_unique<SwBorderAttrAccess>(SwFrm::GetCache(), this);
                     pAttrs = pAccess->Get();
                 }
 
@@ -1910,10 +1911,10 @@ void SwTabFrm::MakeAll(vcl::RenderContext* pRenderContext)
                 ((Prt().*fnRect->fnGetWidth)() != nOldPrtWidth ||
                 (Frm().*fnRect->fnGetWidth)() != nOldFrmWidth) )
             {
-                delete pAccess;
+                pAccess.reset();
                 m_bCalcLowers |= pLayout->Resize(
                     pLayout->GetBrowseWidthByTabFrm( *this ) );
-                pAccess= new SwBorderAttrAccess( SwFrm::GetCache(), this );
+                pAccess = o3tl::make_unique<SwBorderAttrAccess>(SwFrm::GetCache(), this);
                 pAttrs = pAccess->Get();
             }
             if ( aOldPrtPos != (Prt().*fnRect->fnGetPos)() )
@@ -1959,11 +1960,11 @@ void SwTabFrm::MakeAll(vcl::RenderContext* pRenderContext)
                             GetTable()->GetHTMLTableLayout();
                         if( pHTMLLayout )
                         {
-                            delete pAccess;
+                            pAccess.reset();
                             m_bCalcLowers |= pHTMLLayout->Resize(
                                 pHTMLLayout->GetBrowseWidthByTabFrm( *this ) );
 
-                            pAccess= new SwBorderAttrAccess( SwFrm::GetCache(), this );
+                            pAccess = o3tl::make_unique<SwBorderAttrAccess>(SwFrm::GetCache(), this);
                             pAttrs = pAccess->Get();
                         }
 
@@ -2135,7 +2136,7 @@ void SwTabFrm::MakeAll(vcl::RenderContext* pRenderContext)
 
                 if ( bFormat )
                 {
-                    delete pAccess;
+                    pAccess.reset();
 
                     // Consider case that table is inside another table, because
                     // it has to be avoided, that superior table is formatted.
@@ -2143,7 +2144,7 @@ void SwTabFrm::MakeAll(vcl::RenderContext* pRenderContext)
                     // is found, get its first content.
                     const SwFrm* pTmpNxt = sw_FormatNextContentForKeep( this );
 
-                    pAccess= new SwBorderAttrAccess( SwFrm::GetCache(), this );
+                    pAccess = o3tl::make_unique<SwBorderAttrAccess>(SwFrm::GetCache(), this);
                     pAttrs = pAccess->Get();
 
                     // The last row wants to keep with the frame behind the table.
@@ -2374,11 +2375,11 @@ void SwTabFrm::MakeAll(vcl::RenderContext* pRenderContext)
                         {
                             ++nStack;
                             StackHack aHack;
-                            delete pAccess;
+                            pAccess.reset();
 
                             GetFollow()->MakeAll(pRenderContext);
 
-                            pAccess= new SwBorderAttrAccess( SwFrm::GetCache(), this );
+                            pAccess = o3tl::make_unique<SwBorderAttrAccess>(SwFrm::GetCache(), this);
                             pAttrs = pAccess->Get();
 
                             GetFollow()->SetLowersFormatted(false);
@@ -2518,7 +2519,7 @@ void SwTabFrm::MakeAll(vcl::RenderContext* pRenderContext)
     }
 
     m_bCalcLowers = m_bONECalcLowers = false;
-    delete pAccess;
+    pAccess.reset();
     UnlockJoin();
     if ( bMovedFwd || bMovedBwd || !bOldValidPos )
         aNotify.SetInvaKeep();


More information about the Libreoffice-commits mailing list