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

Takeshi Abe tabe at fixedpoint.jp
Sun Aug 3 05:59:10 PDT 2014


 cui/source/tabpages/tpline.cxx   |   62 +++++++++++++++++----------------------
 cui/source/tabpages/tplnedef.cxx |   13 +++-----
 cui/source/tabpages/tplneend.cxx |    7 +---
 3 files changed, 37 insertions(+), 45 deletions(-)

New commits:
commit 8a46be0aba351d116dc094ff6d8b508c18286e21
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date:   Sun Aug 3 12:10:40 2014 +0900

    Avoid possible memory leaks in case of exceptions
    
    Change-Id: I9d8d7aabc111d3700fc121277c49eb0f48dc7e44

diff --git a/cui/source/tabpages/tpline.cxx b/cui/source/tabpages/tpline.cxx
index 4c7fd82..58a9246 100644
--- a/cui/source/tabpages/tpline.cxx
+++ b/cui/source/tabpages/tpline.cxx
@@ -52,6 +52,7 @@
 #include <svx/dialmgr.hxx>
 #include <svx/dialogs.hrc>
 #include <vcl/settings.hxx>
+#include <boost/scoped_ptr.hpp>
 
 #define MAX_BMP_WIDTH   16
 #define MAX_BMP_HEIGHT  16
@@ -316,14 +317,15 @@ void SvxLineTabPage::InitSymbols(MenuButton* pButton)
     {
         VirtualDevice aVDev;
         aVDev.SetMapMode(MapMode(MAP_100TH_MM));
-        SdrModel* pModel = new SdrModel;
+        boost::scoped_ptr<SdrModel> pModel(new SdrModel);
         pModel->GetItemPool().FreezeIdRanges();
         // Page
         SdrPage* pPage = new SdrPage( *pModel, false );
         pPage->SetSize(Size(1000,1000));
         pModel->InsertPage( pPage, 0 );
+        {
         // 3D View
-        SdrView* pView = new SdrView( pModel, &aVDev );
+        boost::scoped_ptr<SdrView> pView(new SdrView( pModel.get(), &aVDev ));
         pView->hideMarkHandles();
         pView->ShowSdrPage(pPage);
 
@@ -393,8 +395,7 @@ void SvxLineTabPage::InitSymbols(MenuButton* pButton)
         if(aGrfNames.empty())
             m_pSymbolMB->GetPopupMenu()->EnableItem(MN_SYMBOLS, false);
 
-        delete pView;
-        delete pModel;
+        }
     }
 }
 
@@ -681,15 +682,15 @@ bool SvxLineTabPage::FillItemSet( SfxItemSet* rAttrs )
         if( nPos != LISTBOX_ENTRY_NOTFOUND &&
             m_pLbLineStyle->IsValueChangedFromSaved() )
         {
-            XLineStyleItem* pStyleItem = NULL;
+            boost::scoped_ptr<XLineStyleItem> pStyleItem;
 
             if( nPos == 0 )
-                pStyleItem = new XLineStyleItem( XLINE_NONE );
+                pStyleItem.reset(new XLineStyleItem( XLINE_NONE ));
             else if( nPos == 1 )
-                pStyleItem = new XLineStyleItem( XLINE_SOLID );
+                pStyleItem.reset(new XLineStyleItem( XLINE_SOLID ));
             else
             {
-                pStyleItem = new XLineStyleItem( XLINE_DASH );
+                pStyleItem.reset(new XLineStyleItem( XLINE_DASH ));
 
                 // For added security
                 if( pDashList->Count() > (long) ( nPos - 2 ) )
@@ -710,7 +711,6 @@ bool SvxLineTabPage::FillItemSet( SfxItemSet* rAttrs )
                 rAttrs->Put( *pStyleItem );
                 bModified = true;
             }
-            delete pStyleItem;
         }
     }
     // Line width
@@ -766,28 +766,27 @@ bool SvxLineTabPage::FillItemSet( SfxItemSet* rAttrs )
         nPos = m_pLbStartStyle->GetSelectEntryPos();
         if( nPos != LISTBOX_ENTRY_NOTFOUND && m_pLbStartStyle->IsValueChangedFromSaved() )
         {
-            XLineStartItem* pItem = NULL;
+            boost::scoped_ptr<XLineStartItem> pItem;
             if( nPos == 0 )
-                pItem = new XLineStartItem();
+                pItem.reset(new XLineStartItem());
             else if( pLineEndList->Count() > (long) ( nPos - 1 ) )
-                pItem = new XLineStartItem( m_pLbStartStyle->GetSelectEntry(), pLineEndList->GetLineEnd( nPos - 1 )->GetLineEnd() );
+                pItem.reset(new XLineStartItem( m_pLbStartStyle->GetSelectEntry(), pLineEndList->GetLineEnd( nPos - 1 )->GetLineEnd() ));
             pOld = GetOldItem( *rAttrs, XATTR_LINESTART );
             if( pItem && ( !pOld || !( *(const XLineEndItem*)pOld == *pItem ) ) )
             {
                 rAttrs->Put( *pItem );
                 bModified = true;
             }
-            delete pItem;
         }
         // Line end
         nPos = m_pLbEndStyle->GetSelectEntryPos();
         if( nPos != LISTBOX_ENTRY_NOTFOUND && m_pLbEndStyle->IsValueChangedFromSaved() )
         {
-            XLineEndItem* pItem = NULL;
+            boost::scoped_ptr<XLineEndItem> pItem;
             if( nPos == 0 )
-                pItem = new XLineEndItem();
+                pItem.reset(new XLineEndItem());
             else if( pLineEndList->Count() > (long) ( nPos - 1 ) )
-                pItem = new XLineEndItem( m_pLbEndStyle->GetSelectEntry(), pLineEndList->GetLineEnd( nPos - 1 )->GetLineEnd() );
+                pItem.reset(new XLineEndItem( m_pLbEndStyle->GetSelectEntry(), pLineEndList->GetLineEnd( nPos - 1 )->GetLineEnd() ));
             pOld = GetOldItem( *rAttrs, XATTR_LINEEND );
             if( pItem &&
                 ( !pOld || !( *(const XLineEndItem*)pOld == *pItem ) ) )
@@ -795,7 +794,6 @@ bool SvxLineTabPage::FillItemSet( SfxItemSet* rAttrs )
                 rAttrs->Put( *pItem );
                 bModified = true;
             }
-            delete pItem;
         }
     }
 
@@ -840,28 +838,28 @@ bool SvxLineTabPage::FillItemSet( SfxItemSet* rAttrs )
     nPos = m_pLBEdgeStyle->GetSelectEntryPos();
     if( LISTBOX_ENTRY_NOTFOUND != nPos && m_pLBEdgeStyle->IsValueChangedFromSaved() )
     {
-        XLineJointItem* pNew = 0L;
+        boost::scoped_ptr<XLineJointItem> pNew;
 
         switch(nPos)
         {
             case 0: // Rounded, default
             {
-                pNew = new XLineJointItem(com::sun::star::drawing::LineJoint_ROUND);
+                pNew.reset(new XLineJointItem(com::sun::star::drawing::LineJoint_ROUND));
                 break;
             }
             case 1: // - none -
             {
-                pNew = new XLineJointItem(com::sun::star::drawing::LineJoint_NONE);
+                pNew.reset(new XLineJointItem(com::sun::star::drawing::LineJoint_NONE));
                 break;
             }
             case 2: // Miter
             {
-                pNew = new XLineJointItem(com::sun::star::drawing::LineJoint_MITER);
+                pNew.reset(new XLineJointItem(com::sun::star::drawing::LineJoint_MITER));
                 break;
             }
             case 3: // Bevel
             {
-                pNew = new XLineJointItem(com::sun::star::drawing::LineJoint_BEVEL);
+                pNew.reset(new XLineJointItem(com::sun::star::drawing::LineJoint_BEVEL));
                 break;
             }
         }
@@ -875,8 +873,6 @@ bool SvxLineTabPage::FillItemSet( SfxItemSet* rAttrs )
                 rAttrs->Put( *pNew );
                 bModified = true;
             }
-
-            delete pNew;
         }
     }
 
@@ -884,23 +880,23 @@ bool SvxLineTabPage::FillItemSet( SfxItemSet* rAttrs )
     nPos = m_pLBCapStyle->GetSelectEntryPos();
     if( LISTBOX_ENTRY_NOTFOUND != nPos && m_pLBCapStyle->IsValueChangedFromSaved() )
     {
-        XLineCapItem* pNew = 0L;
+        boost::scoped_ptr<XLineCapItem> pNew;
 
         switch(nPos)
         {
             case 0: // Butt (=Flat), default
             {
-                pNew = new XLineCapItem(com::sun::star::drawing::LineCap_BUTT);
+                pNew.reset(new XLineCapItem(com::sun::star::drawing::LineCap_BUTT));
                 break;
             }
             case 1: // Round
             {
-                pNew = new XLineCapItem(com::sun::star::drawing::LineCap_ROUND);
+                pNew.reset(new XLineCapItem(com::sun::star::drawing::LineCap_ROUND));
                 break;
             }
             case 2: // Square
             {
-                pNew = new XLineCapItem(com::sun::star::drawing::LineCap_SQUARE);
+                pNew.reset(new XLineCapItem(com::sun::star::drawing::LineCap_SQUARE));
                 break;
             }
         }
@@ -914,8 +910,6 @@ bool SvxLineTabPage::FillItemSet( SfxItemSet* rAttrs )
                 rAttrs->Put( *pNew );
                 bModified = true;
             }
-
-            delete pNew;
         }
     }
 
@@ -1119,12 +1113,13 @@ void SvxLineTabPage::Reset( const SfxItemSet* rAttrs )
         VirtualDevice aVDev;
         aVDev.SetMapMode(MapMode(MAP_100TH_MM));
 
-        SdrModel* pModel = new SdrModel;
+        boost::scoped_ptr<SdrModel> pModel(new SdrModel);
         pModel->GetItemPool().FreezeIdRanges();
         SdrPage* pPage = new SdrPage( *pModel, false );
         pPage->SetSize(Size(1000,1000));
         pModel->InsertPage( pPage, 0 );
-        SdrView* pView = new SdrView( pModel, &aVDev );
+        {
+        boost::scoped_ptr<SdrView> pView(new SdrView( pModel.get(), &aVDev ));
         pView->hideMarkHandles();
         pView->ShowSdrPage(pPage);
         SdrObject *pObj=NULL;
@@ -1176,8 +1171,7 @@ void SvxLineTabPage::Reset( const SfxItemSet* rAttrs )
                 }
             }
         }
-        delete pView;
-        delete pModel;
+        }
     }
     if(rAttrs->GetItemState(rAttrs->GetPool()->GetWhich(SID_ATTR_BRUSH),true,&pPoolItem) == SFX_ITEM_SET)
     {
diff --git a/cui/source/tabpages/tplnedef.cxx b/cui/source/tabpages/tplnedef.cxx
index 92e3687..a221f6e 100644
--- a/cui/source/tabpages/tplnedef.cxx
+++ b/cui/source/tabpages/tplnedef.cxx
@@ -43,6 +43,7 @@
 #include "svx/dlgutil.hxx"
 #include <svx/dialmgr.hxx>
 #include <svx/dialogs.hrc>
+#include <boost/scoped_ptr.hpp>
 
 #define XOUT_WIDTH    150
 
@@ -216,10 +217,10 @@ void SvxLineDefTabPage::CheckChanges_Impl()
     {
         ResMgr& rMgr = CUI_MGR();
         Image aWarningBoxImage = WarningBox::GetStandardImage();
-        SvxMessDialog* aMessDlg = new SvxMessDialog(GetParentDialog(),
+        boost::scoped_ptr<SvxMessDialog> aMessDlg(new SvxMessDialog(GetParentDialog(),
                                                     SVX_RESSTR( RID_SVXSTR_LINESTYLE ),
                                                     OUString( ResId( RID_SVXSTR_ASK_CHANGE_LINESTYLE, rMgr ) ),
-                                                    &aWarningBoxImage );
+                                                    &aWarningBoxImage ));
         DBG_ASSERT(aMessDlg, "Dialog creation failed!");
         aMessDlg->SetButtonText( MESS_BTN_1, OUString( ResId( RID_SVXSTR_CHANGE, rMgr ) ) );
         aMessDlg->SetButtonText( MESS_BTN_2, OUString( ResId( RID_SVXSTR_ADD, rMgr ) ) );
@@ -243,7 +244,6 @@ void SvxLineDefTabPage::CheckChanges_Impl()
             case RET_CANCEL:
             break;
         }
-        delete aMessDlg;
     }
 
 
@@ -545,7 +545,7 @@ IMPL_LINK_NOARG(SvxLineDefTabPage, ClickAddHdl_Impl)
 
     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     DBG_ASSERT(pFact, "Dialog creation failed!");
-    AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( GetParentDialog(), aName, aDesc );
+    boost::scoped_ptr<AbstractSvxNameDialog> pDlg(pFact->CreateSvxNameDialog( GetParentDialog(), aName, aDesc ));
     DBG_ASSERT(pDlg, "Dialog creation failed!");
     bool bLoop = true;
 
@@ -596,7 +596,7 @@ IMPL_LINK_NOARG(SvxLineDefTabPage, ClickAddHdl_Impl)
             aBox.Execute();
         }
     }
-    delete( pDlg );
+    pDlg.reset();
 
     // determine button state
     if ( pDashList->Count() )
@@ -623,7 +623,7 @@ IMPL_LINK_NOARG(SvxLineDefTabPage, ClickModifyHdl_Impl)
 
         SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
         DBG_ASSERT(pFact, "Dialog creation failed!");
-        AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( GetParentDialog(), aName, aDesc );
+        boost::scoped_ptr<AbstractSvxNameDialog> pDlg(pFact->CreateSvxNameDialog( GetParentDialog(), aName, aDesc ));
         DBG_ASSERT(pDlg, "Dialog creation failed!");
 
         long nCount = pDashList->Count();
@@ -675,7 +675,6 @@ IMPL_LINK_NOARG(SvxLineDefTabPage, ClickModifyHdl_Impl)
                 aBox.Execute();
             }
         }
-        delete( pDlg );
     }
     return( 0L );
 }
diff --git a/cui/source/tabpages/tplneend.cxx b/cui/source/tabpages/tplneend.cxx
index da58cdb..4390554 100644
--- a/cui/source/tabpages/tplneend.cxx
+++ b/cui/source/tabpages/tplneend.cxx
@@ -45,6 +45,7 @@
 #include <basegfx/polygon/b2dpolypolygontools.hxx>
 #include <basegfx/matrix/b2dhommatrixtools.hxx>
 #include <svx/dialogs.hrc>
+#include <boost/scoped_ptr.hpp>
 
 #define XOUT_WIDTH    150
 
@@ -333,7 +334,7 @@ IMPL_LINK_NOARG(SvxLineEndDefTabPage, ClickModifyHdl_Impl)
 
             SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
             DBG_ASSERT(pFact, "Dialog creation failed!");
-            AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( GetParentDialog(), aName, aDesc );
+            boost::scoped_ptr<AbstractSvxNameDialog> pDlg(pFact->CreateSvxNameDialog( GetParentDialog(), aName, aDesc ));
             DBG_ASSERT(pDlg, "Dialog creation failed!");
             bool bLoop = true;
 
@@ -353,7 +354,6 @@ IMPL_LINK_NOARG(SvxLineEndDefTabPage, ClickModifyHdl_Impl)
                 else
                     aWarningBox.Execute();
             }
-            delete( pDlg );
         }
 
         // if not existing, enter the entry
@@ -448,7 +448,7 @@ IMPL_LINK_NOARG(SvxLineEndDefTabPage, ClickAddHdl_Impl)
 
         SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
         DBG_ASSERT(pFact, "Dialog creation failed!");
-        AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( GetParentDialog(), aName, aDesc );
+        boost::scoped_ptr<AbstractSvxNameDialog> pDlg(pFact->CreateSvxNameDialog( GetParentDialog(), aName, aDesc ));
         DBG_ASSERT(pDlg, "Dialog creation failed!");
         bool bLoop = true;
 
@@ -487,7 +487,6 @@ IMPL_LINK_NOARG(SvxLineEndDefTabPage, ClickAddHdl_Impl)
                 aBox.Execute();
             }
         }
-        delete pDlg;
     }
     else
         m_pBtnAdd->Disable();


More information about the Libreoffice-commits mailing list