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

Takeshi Abe tabe at fixedpoint.jp
Thu Jun 12 11:59:35 PDT 2014


 sw/source/uibase/shells/mediash.cxx |    9 +++------
 sw/source/uibase/shells/tabsh.cxx   |   30 ++++++++++++------------------
 sw/source/uibase/shells/textfld.cxx |   15 ++++++---------
 sw/source/uibase/shells/textidx.cxx |   12 +++++-------
 sw/source/uibase/shells/textsh.cxx  |   16 ++++++----------
 5 files changed, 32 insertions(+), 50 deletions(-)

New commits:
commit 3d3fc58a32211cf56c5238f2d9f0e86a1eb7ae7e
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date:   Fri Jun 13 03:56:40 2014 +0900

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

diff --git a/sw/source/uibase/shells/mediash.cxx b/sw/source/uibase/shells/mediash.cxx
index d4c257e..0664138 100644
--- a/sw/source/uibase/shells/mediash.cxx
+++ b/sw/source/uibase/shells/mediash.cxx
@@ -67,6 +67,7 @@
 #include <sfx2/msg.hxx>
 #include "swslots.hxx"
 #include "swabstdlg.hxx"
+#include <boost/scoped_ptr.hpp>
 
 SFX_IMPL_INTERFACE(SwMediaShell, SwBaseShell, SW_RES(STR_SHELLNAME_MEDIA))
 
@@ -118,7 +119,7 @@ void SwMediaShell::ExecMedia(SfxRequest &rReq)
 
                     if( pItem )
                     {
-                        SdrMarkList* pMarkList = new SdrMarkList( pSdrView->GetMarkedObjectList() );
+                        boost::scoped_ptr<SdrMarkList> pMarkList(new SdrMarkList( pSdrView->GetMarkedObjectList() ));
 
                         if( 1 == pMarkList->GetMarkCount() )
                         {
@@ -130,8 +131,6 @@ void SwMediaShell::ExecMedia(SfxRequest &rReq)
                                     static_cast< const ::avmedia::MediaItem& >( *pItem ) );
                             }
                         }
-
-                        delete pMarkList;
                     }
                 }
             }
@@ -163,7 +162,7 @@ void SwMediaShell::GetMediaState(SfxItemSet &rSet)
             if( pView )
             {
                 bool bDisable = true;
-                SdrMarkList* pMarkList = new SdrMarkList( pView->GetMarkedObjectList() );
+                boost::scoped_ptr<SdrMarkList> pMarkList(new SdrMarkList( pView->GetMarkedObjectList() ));
 
                 if( 1 == pMarkList->GetMarkCount() )
                 {
@@ -181,8 +180,6 @@ void SwMediaShell::GetMediaState(SfxItemSet &rSet)
 
                 if( bDisable )
                     rSet.DisableItem( SID_AVMEDIA_TOOLBOX );
-
-                delete pMarkList;
             }
         }
 
diff --git a/sw/source/uibase/shells/tabsh.cxx b/sw/source/uibase/shells/tabsh.cxx
index 2b3a60d..338238d 100644
--- a/sw/source/uibase/shells/tabsh.cxx
+++ b/sw/source/uibase/shells/tabsh.cxx
@@ -560,13 +560,13 @@ void SwTableShell::Execute(SfxRequest &rReq)
 
             FieldUnit eMetric = ::GetDfltMetric(0 != PTR_CAST(SwWebView, &rSh.GetView()));
             SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< sal_uInt16 >(eMetric)));
-            SwTableRep* pTblRep = ::lcl_TableParamToItemSet( aCoreSet, rSh );
-            SfxAbstractTabDialog * pDlg = NULL;
+            boost::scoped_ptr<SwTableRep> pTblRep(::lcl_TableParamToItemSet( aCoreSet, rSh ));
+            boost::scoped_ptr<SfxAbstractTabDialog> pDlg;
             {
                 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
                 OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
 
-                pDlg = pFact->CreateSwTableTabDlg(GetView().GetWindow(), GetPool(), &aCoreSet, &rSh);
+                pDlg.reset(pFact->CreateSwTableTabDlg(GetView().GetWindow(), GetPool(), &aCoreSet, &rSh));
                 OSL_ENSURE(pDlg, "Dialogdiet fail!");
 
                 if (pItem)
@@ -593,8 +593,8 @@ void SwTableShell::Execute(SfxRequest &rReq)
                 ItemSetToTableParam( *pOutSet, rSh );
             }
 
-            delete pDlg;
-            delete pTblRep;
+            pDlg.reset();
+            pTblRep.reset();
             rBindings.Update(SID_RULER_BORDERS);
             rBindings.Update(SID_ATTR_TABSTOP);
             rBindings.Update(SID_RULER_BORDERS_VERTICAL);
@@ -646,9 +646,9 @@ void SwTableShell::Execute(SfxRequest &rReq)
                 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
                 OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
 
-                SfxAbstractDialog* pDlg = pFact->CreateSfxDialog( GetView().GetWindow(),aCoreSet,
+                boost::scoped_ptr<SfxAbstractDialog> pDlg(pFact->CreateSfxDialog( GetView().GetWindow(),aCoreSet,
                     pView->GetViewFrame()->GetFrame().GetFrameInterface(),
-                    RC_DLG_SWNUMFMTDLG );
+                    RC_DLG_SWNUMFMTDLG ));
                 OSL_ENSURE(pDlg, "Dialogdiet fail!");
 
                 if (RET_OK == pDlg->Execute())
@@ -677,7 +677,6 @@ void SwTableShell::Execute(SfxRequest &rReq)
 
                     }
                 }
-                delete pDlg;
             }
         }
         break;
@@ -794,10 +793,9 @@ void SwTableShell::Execute(SfxRequest &rReq)
             SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
             OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
 
-            AbstractSwAutoFormatDlg* pDlg = pFact->CreateSwAutoFormatDlg(&GetView().GetViewFrame()->GetWindow(), &rSh);
+            boost::scoped_ptr<AbstractSwAutoFormatDlg> pDlg(pFact->CreateSwAutoFormatDlg(&GetView().GetViewFrame()->GetWindow(), &rSh));
             OSL_ENSURE(pDlg, "Dialogdiet fail!");
             pDlg->Execute();
-            delete pDlg;
         }
         break;
         case FN_TABLE_SET_ROW_HEIGHT:
@@ -805,10 +803,9 @@ void SwTableShell::Execute(SfxRequest &rReq)
             SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
             OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
 
-            VclAbstractDialog* pDlg = pFact->CreateVclAbstractDialog( GetView().GetWindow(), rSh, DLG_ROW_HEIGHT );
+            boost::scoped_ptr<VclAbstractDialog> pDlg(pFact->CreateVclAbstractDialog( GetView().GetWindow(), rSh, DLG_ROW_HEIGHT ));
             OSL_ENSURE(pDlg, "Dialogdiet fail!");
             pDlg->Execute();
-            delete pDlg;
         }
         break;
         case FN_NUMBER_BULLETS:
@@ -918,7 +915,7 @@ void SwTableShell::Execute(SfxRequest &rReq)
                 if( pFact )
                 {
                     const long nMaxVert = rSh.GetAnyCurRect( RECT_FRM ).Width() / MINLAY;
-                    SvxAbstractSplittTableDialog* pDlg = pFact->CreateSvxSplittTableDialog( GetView().GetWindow(), rSh.IsTableVertical(), nMaxVert, 99 );
+                    boost::scoped_ptr<SvxAbstractSplittTableDialog> pDlg(pFact->CreateSvxSplittTableDialog( GetView().GetWindow(), rSh.IsTableVertical(), nMaxVert, 99 ));
                     if( pDlg && (pDlg->Execute() == RET_OK) )
                     {
                         nCount = pDlg->GetCount();
@@ -928,7 +925,6 @@ void SwTableShell::Execute(SfxRequest &rReq)
                         rReq.AppendItem( SfxBoolItem( FN_PARAM_1, bHorizontal ) );
                         rReq.AppendItem( SfxBoolItem( FN_PARAM_2, bProportional ) );
                     }
-                    delete pDlg;
                 }
             }
 
@@ -963,11 +959,10 @@ void SwTableShell::Execute(SfxRequest &rReq)
                 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
                 OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
 
-                AbstractSplitTableDialog* pDlg = pFact->CreateSplitTblDialog( GetView().GetWindow(), rSh );
+                boost::scoped_ptr<AbstractSplitTableDialog> pDlg(pFact->CreateSplitTblDialog( GetView().GetWindow(), rSh ));
                 OSL_ENSURE(pDlg, "Dialogdiet fail!");
                 pDlg->Execute();
                 rReq.AppendItem( SfxUInt16Item( FN_PARAM_1, pDlg->GetSplitMode() ) );
-                delete pDlg;
                 bCallDone = true;
             }
         }
@@ -982,11 +977,10 @@ void SwTableShell::Execute(SfxRequest &rReq)
             {
                 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
                 OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
-                VclAbstractDialog* pDlg = pFact->CreateTblMergeDialog(GetView().GetWindow(), bPrev);
+                boost::scoped_ptr<VclAbstractDialog> pDlg(pFact->CreateTblMergeDialog(GetView().GetWindow(), bPrev));
                 OSL_ENSURE(pDlg, "dialogdiet pDlg fail!");
                 if( RET_OK != pDlg->Execute())
                     bPrev = bNext = false;
-                delete pDlg;
             }
 
             if( bPrev || bNext )
diff --git a/sw/source/uibase/shells/textfld.cxx b/sw/source/uibase/shells/textfld.cxx
index ce20366..3c87e91 100644
--- a/sw/source/uibase/shells/textfld.cxx
+++ b/sw/source/uibase/shells/textfld.cxx
@@ -69,6 +69,7 @@
 #include <edtwin.hxx>
 #include <PostItMgr.hxx>
 #include <switerator.hxx>
+#include <boost/scoped_ptr.hpp>
 
 using namespace nsSwDocInfoSubType;
 
@@ -123,11 +124,10 @@ void SwTextShell::ExecField(SfxRequest &rReq)
                         if(rLink.IsVisible())
                         {
                             SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
-                            SfxAbstractLinksDialog* pDlg = pFact->CreateLinksDialog( pMDI, &rSh.GetLinkManager(), false, &rLink );
+                            boost::scoped_ptr<SfxAbstractLinksDialog> pDlg(pFact->CreateLinksDialog( pMDI, &rSh.GetLinkManager(), false, &rLink ));
                             if ( pDlg )
                             {
                                 pDlg->Execute();
-                                delete pDlg;
                             }
                         }
                         break;
@@ -137,10 +137,9 @@ void SwTextShell::ExecField(SfxRequest &rReq)
                         SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
                         OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
 
-                        SfxAbstractDialog* pDlg = pFact->CreateSwFldEditDlg( GetView(),RC_DLG_SWFLDEDITDLG );
+                        boost::scoped_ptr<SfxAbstractDialog> pDlg(pFact->CreateSwFldEditDlg( GetView(),RC_DLG_SWFLDEDITDLG ));
                         OSL_ENSURE(pDlg, "Dialogdiet fail!");
                         pDlg->Execute();
-                        delete pDlg;
                     }
                 }
             }
@@ -474,7 +473,7 @@ void SwTextShell::ExecField(SfxRequest &rReq)
 
                     SvxAbstractDialogFactory* pFact2 = SvxAbstractDialogFactory::Create();
                     OSL_ENSURE(pFact2, "Dialogdiet fail!");
-                    AbstractSvxPostItDialog* pDlg = pFact2->CreateSvxPostItDialog( pMDI, aSet, bTravel );
+                    boost::scoped_ptr<AbstractSvxPostItDialog> pDlg(pFact2->CreateSvxPostItDialog( pMDI, aSet, bTravel ));
                     OSL_ENSURE(pDlg, "Dialogdiet fail!");
                     pDlg->HideAuthor();
 
@@ -502,7 +501,7 @@ void SwTextShell::ExecField(SfxRequest &rReq)
                         rSh.SetRedlineComment(sMsg);
                     }
 
-                    delete pDlg;
+                    pDlg.reset();
                     rSh.SetCareWin(NULL);
                     bNoInterrupt = false;
                     rSh.ClearMark();
@@ -536,7 +535,7 @@ void SwTextShell::ExecField(SfxRequest &rReq)
                 {
                     SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
                     OSL_ENSURE(pFact, "Dialogdiet fail!");
-                    AbstractJavaEditDialog* pDlg = pFact->CreateJavaEditDialog(pMDI, &rSh);
+                    boost::scoped_ptr<AbstractJavaEditDialog> pDlg(pFact->CreateJavaEditDialog(pMDI, &rSh));
                     OSL_ENSURE(pDlg, "Dialogdiet fail!");
                     if ( pDlg->Execute() )
                     {
@@ -549,8 +548,6 @@ void SwTextShell::ExecField(SfxRequest &rReq)
                         rReq.AppendItem( SfxStringItem( FN_PARAM_2, aType ) );
                         rReq.AppendItem( SfxBoolItem( FN_PARAM_1, bIsUrl ) );
                     }
-
-                    delete pDlg;
                 }
 
                 if( bNew )
diff --git a/sw/source/uibase/shells/textidx.cxx b/sw/source/uibase/shells/textidx.cxx
index 5bf3272..b6f55f3 100644
--- a/sw/source/uibase/shells/textidx.cxx
+++ b/sw/source/uibase/shells/textidx.cxx
@@ -39,6 +39,7 @@
 #include "swabstdlg.hxx"
 #include <index.hrc>
 #include <globals.hrc>
+#include <boost/scoped_ptr.hpp>
 
 void SwTextShell::ExecIdx(SfxRequest &rReq)
 {
@@ -57,10 +58,9 @@ void SwTextShell::ExecIdx(SfxRequest &rReq)
         {
             SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
             OSL_ENSURE(pFact, "Dialogdiet fail!");
-            VclAbstractDialog* pDlg = pFact->CreateVclAbstractDialog( pMDI, GetShell(), DLG_EDIT_AUTHMARK);
+            boost::scoped_ptr<VclAbstractDialog> pDlg(pFact->CreateVclAbstractDialog( pMDI, GetShell(), DLG_EDIT_AUTHMARK));
             OSL_ENSURE(pDlg, "Dialogdiet fail!");
             pDlg->Execute();
-            delete pDlg;
         }
         break;
         case FN_INSERT_AUTH_ENTRY_DLG:
@@ -93,10 +93,9 @@ void SwTextShell::ExecIdx(SfxRequest &rReq)
             {
                 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
                 OSL_ENSURE(pFact, "Dialogdiet fail!");
-                VclAbstractDialog* pDlg = pFact->CreateIndexMarkModalDlg(pMDI, GetShell(), aMgr.GetCurTOXMark());
+                boost::scoped_ptr<VclAbstractDialog> pDlg(pFact->CreateIndexMarkModalDlg(pMDI, GetShell(), aMgr.GetCurTOXMark()));
                 OSL_ENSURE(pDlg, "Dialogdiet fail!");
                 pDlg->Execute();
-                delete pDlg;
             }
             break;
         }
@@ -140,12 +139,11 @@ void SwTextShell::ExecIdx(SfxRequest &rReq)
             }
             SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
             OSL_ENSURE(pFact, "Dialogdiet fail!");
-            AbstractMultiTOXTabDialog* pDlg = pFact->CreateMultiTOXTabDialog(
+            boost::scoped_ptr<AbstractMultiTOXTabDialog> pDlg(pFact->CreateMultiTOXTabDialog(
                                                         pMDI, aSet, rSh, (SwTOXBase* )pCurTOX,
-                                                        USHRT_MAX, bGlobal);
+                                                        USHRT_MAX, bGlobal));
             OSL_ENSURE(pDlg, "Dialogdiet fail!");
             pDlg->Execute();
-            delete pDlg;
         }
         break;
         case FN_REMOVE_CUR_TOX:
diff --git a/sw/source/uibase/shells/textsh.cxx b/sw/source/uibase/shells/textsh.cxx
index 25499dc..190c81f 100644
--- a/sw/source/uibase/shells/textsh.cxx
+++ b/sw/source/uibase/shells/textsh.cxx
@@ -113,6 +113,7 @@ using namespace ::com::sun::star;
 #include <table.hrc>
 #include <frmui.hrc>
 #include <unomid.h>
+#include <boost/scoped_ptr.hpp>
 
 SFX_IMPL_INTERFACE(SwTextShell, SwBaseShell, SW_RES(STR_SHELLNAME_TEXT))
 
@@ -607,10 +608,10 @@ void SwTextShell::ExecInsert(SfxRequest &rReq)
             SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< sal_uInt16 >(eMetric)));
             SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
             OSL_ENSURE(pFact, "Dialogdiet fail!");
-            SfxAbstractTabDialog* pDlg = pFact->CreateFrmTabDialog("FrameDialog",
+            boost::scoped_ptr<SfxAbstractTabDialog> pDlg(pFact->CreateFrmTabDialog("FrameDialog",
                                                     GetView().GetViewFrame(),
                                                     &GetView().GetViewFrame()->GetWindow(),
-                                                    aSet, true);
+                                                    aSet, true));
             OSL_ENSURE(pDlg, "Dialogdiet fail!");
             if(pDlg->Execute() == RET_OK && pDlg->GetOutputItemSet())
             {
@@ -653,8 +654,6 @@ void SwTextShell::ExecInsert(SfxRequest &rReq)
                 rShell.EndAllAction();
                 rShell.UnlockPaint();
             }
-
-            DELETEZ(pDlg);
         }
         break;
     }
@@ -662,10 +661,9 @@ void SwTextShell::ExecInsert(SfxRequest &rReq)
     {
         SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
         OSL_ENSURE(pFact, "Dialogdiet fail!");
-        VclAbstractDialog* pColDlg = pFact->CreateVclAbstractDialog( GetView().GetWindow(), rSh, DLG_COLUMN);
+        boost::scoped_ptr<VclAbstractDialog> pColDlg(pFact->CreateVclAbstractDialog( GetView().GetWindow(), rSh, DLG_COLUMN));
         OSL_ENSURE(pColDlg, "Dialogdiet fail!");
         pColDlg->Execute();
-        delete pColDlg;
     }
     break;
 
@@ -1021,8 +1019,8 @@ void SwTextShell::InsertSymbol( SfxRequest& rReq )
             aAllSet.Put( SfxStringItem( SID_FONT_NAME, aFont.GetFamilyName() ) );
 
         SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
-        SfxAbstractDialog* pDlg = pFact->CreateSfxDialog( GetView().GetWindow(), aAllSet,
-            GetView().GetViewFrame()->GetFrame().GetFrameInterface(), RID_SVXDLG_CHARMAP );
+        boost::scoped_ptr<SfxAbstractDialog> pDlg(pFact->CreateSfxDialog( GetView().GetWindow(), aAllSet,
+            GetView().GetViewFrame()->GetFrame().GetFrameInterface(), RID_SVXDLG_CHARMAP ));
         if( RET_OK == pDlg->Execute() )
         {
             SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pCItem, SfxStringItem, SID_CHARMAP, false );
@@ -1042,8 +1040,6 @@ void SwTextShell::InsertSymbol( SfxRequest& rReq )
                 SW_MOD()->ApplyUsrPref(aOpt, &GetView());
             }
         }
-
-        delete pDlg;
     }
 
     if( !aChars.isEmpty() )


More information about the Libreoffice-commits mailing list