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

Takeshi Abe tabe at fixedpoint.jp
Thu May 15 07:45:54 PDT 2014


 sc/source/ui/dbgui/pvfundlg.cxx   |    4 ++--
 sc/source/ui/docshell/docsh3.cxx  |    6 ++----
 sc/source/ui/docshell/docsh4.cxx  |   22 ++++++++++------------
 sc/source/ui/drawfunc/drawsh.cxx  |   30 ++++++++++--------------------
 sc/source/ui/drawfunc/drawsh5.cxx |    9 +++------
 5 files changed, 27 insertions(+), 44 deletions(-)

New commits:
commit e9c5f63f80ea54aea9963a6c268ed03881d7b734
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date:   Thu May 15 23:32:47 2014 +0900

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

diff --git a/sc/source/ui/dbgui/pvfundlg.cxx b/sc/source/ui/dbgui/pvfundlg.cxx
index 59cf31e..7aca31e 100644
--- a/sc/source/ui/dbgui/pvfundlg.cxx
+++ b/sc/source/ui/dbgui/pvfundlg.cxx
@@ -39,6 +39,7 @@
 #include "dputil.hxx"
 
 #include <vector>
+#include <boost/scoped_ptr.hpp>
 
 using namespace ::com::sun::star::sheet;
 
@@ -499,10 +500,9 @@ IMPL_LINK( ScDPSubtotalDlg, ClickHdl, PushButton*, pBtn )
 {
     if (pBtn == mpBtnOptions)
     {
-        ScDPSubtotalOptDlg* pDlg = new ScDPSubtotalOptDlg( this, mrDPObj, maLabelData, mrDataFields, mbEnableLayout );
+        boost::scoped_ptr<ScDPSubtotalOptDlg> pDlg(new ScDPSubtotalOptDlg( this, mrDPObj, maLabelData, mrDataFields, mbEnableLayout ));
         if( pDlg->Execute() == RET_OK )
             pDlg->FillLabelData( maLabelData );
-        delete pDlg;
     }
     return 0;
 }
diff --git a/sc/source/ui/docshell/docsh3.cxx b/sc/source/ui/docshell/docsh3.cxx
index 33bb671..f297c53 100644
--- a/sc/source/ui/docshell/docsh3.cxx
+++ b/sc/source/ui/docshell/docsh3.cxx
@@ -61,7 +61,7 @@
 #include "conflictsdlg.hxx"
 #include "globstr.hrc"
 #include "markdata.hxx"
-
+#include <boost/scoped_ptr.hpp>
 
 //          Redraw - Benachrichtigungen
 
@@ -653,11 +653,9 @@ void ScDocShell::ExecuteChangeCommentDialog( ScChangeAction* pAction, Window* pP
     aSet.Put( SvxPostItAuthorItem( aAuthor,  SID_ATTR_POSTIT_AUTHOR ) );
     aSet.Put( SvxPostItDateItem  ( aDate,    SID_ATTR_POSTIT_DATE ) );
 
-    ScRedComDialog* pDlg = new ScRedComDialog( pParent, aSet,this,pAction,bPrevNext);
+    boost::scoped_ptr<ScRedComDialog> pDlg(new ScRedComDialog( pParent, aSet,this,pAction,bPrevNext));
 
     pDlg->Execute();
-
-    delete pDlg;
 }
 
 void ScDocShell::CompareDocument( ScDocument& rOtherDoc )
diff --git a/sc/source/ui/docshell/docsh4.cxx b/sc/source/ui/docshell/docsh4.cxx
index 3212694..dd9eaf8 100644
--- a/sc/source/ui/docshell/docsh4.cxx
+++ b/sc/source/ui/docshell/docsh4.cxx
@@ -97,6 +97,7 @@ using namespace ::com::sun::star;
 #include "conditio.hxx"
 #include "sheetevents.hxx"
 #include <documentlinkmgr.hxx>
+#include <boost/scoped_ptr.hpp>
 
 #define IS_SHARE_HEADER(set) \
     ((SfxBoolItem&) \
@@ -328,7 +329,7 @@ void ScDocShell::Execute( SfxRequest& rReq )
                         ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
                         OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
 
-                        AbstractScColRowLabelDlg* pDlg = pFact->CreateScColRowLabelDlg(pParent, bRowHeaders, bColHeaders);
+                        boost::scoped_ptr<AbstractScColRowLabelDlg> pDlg(pFact->CreateScColRowLabelDlg(pParent, bRowHeaders, bColHeaders));
                         OSL_ENSURE(pDlg, "Dialog create fail!");
                         if ( pDlg->Execute() == RET_OK )
                         {
@@ -340,7 +341,6 @@ void ScDocShell::Execute( SfxRequest& rReq )
                         }
                         else
                             bOk = false;
-                        delete pDlg;
                     }
 
                     if (bOk)            // ausfuehren
@@ -865,7 +865,7 @@ void ScDocShell::Execute( SfxRequest& rReq )
                                 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
                                 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
 
-                                AbstractScNewScenarioDlg* pNewDlg = pFact->CreateScNewScenarioDlg(GetActiveDialogParent(), aName, true, bSheetProtected);
+                                boost::scoped_ptr<AbstractScNewScenarioDlg> pNewDlg(pFact->CreateScNewScenarioDlg(GetActiveDialogParent(), aName, true, bSheetProtected));
                                 OSL_ENSURE(pNewDlg, "Dialog create fail!");
                                 pNewDlg->SetScenarioData( aName, aComment, aColor, nFlags );
                                 if ( pNewDlg->Execute() == RET_OK )
@@ -874,7 +874,6 @@ void ScDocShell::Execute( SfxRequest& rReq )
                                     ModifyScenario( nTab, aName, aComment, aColor, nFlags );
                                     rReq.Done();
                                 }
-                                delete pNewDlg;
                             }
                         }
                     }
@@ -1137,8 +1136,8 @@ bool ScDocShell::ExecuteChangeProtectionDialog( Window* _pParent, bool bJustQuer
         OUString aText( ScResId( SCSTR_PASSWORD ) );
         OUString aPassword;
 
-        SfxPasswordDialog* pDlg = new SfxPasswordDialog(
-            _pParent ? _pParent : GetActiveDialogParent(), &aText );
+        boost::scoped_ptr<SfxPasswordDialog> pDlg(new SfxPasswordDialog(
+            _pParent ? _pParent : GetActiveDialogParent(), &aText ));
         pDlg->SetText( aTitle );
         pDlg->SetMinLen( 1 );
         pDlg->SetHelpId( GetStaticInterface()->GetSlot(SID_CHG_PROTECT)->GetCommand() );
@@ -1147,7 +1146,7 @@ bool ScDocShell::ExecuteChangeProtectionDialog( Window* _pParent, bool bJustQuer
             pDlg->ShowExtras( SHOWEXTRAS_CONFIRM );
         if ( pDlg->Execute() == RET_OK )
             aPassword = pDlg->GetPassword();
-        delete pDlg;
+        pDlg.reset();
 
         if (!aPassword.isEmpty())
         {
@@ -1546,7 +1545,7 @@ void ScDocShell::ExecutePageStyle( SfxViewShell& rCaller,
                         ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
                         OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
 
-                        SfxAbstractTabDialog* pDlg = pFact->CreateScStyleDlg( GetActiveDialogParent(), *pStyleSheet, RID_SCDLG_STYLES_PAGE, RID_SCDLG_STYLES_PAGE );
+                        boost::scoped_ptr<SfxAbstractTabDialog> pDlg(pFact->CreateScStyleDlg( GetActiveDialogParent(), *pStyleSheet, RID_SCDLG_STYLES_PAGE, RID_SCDLG_STYLES_PAGE ));
                         OSL_ENSURE(pDlg, "Dialog create fail!");
 
                         if ( pDlg->Execute() == RET_OK )
@@ -1586,7 +1585,7 @@ void ScDocShell::ExecutePageStyle( SfxViewShell& rCaller,
                             PageStyleModified( aNewName, false );
                             rReq.Done();
                         }
-                        delete pDlg;
+                        pDlg.reset();
 
                         rStyleSet.ClearItem( ATTR_PAGE_PAPERTRAY );
                     }
@@ -1701,11 +1700,11 @@ void ScDocShell::ExecutePageStyle( SfxViewShell& rCaller,
                         ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
                         OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
 
-                        SfxAbstractTabDialog* pDlg = pFact->CreateScHFEditDlg( SfxViewFrame::Current(),
+                        boost::scoped_ptr<SfxAbstractTabDialog> pDlg(pFact->CreateScHFEditDlg( SfxViewFrame::Current(),
                                                                                 GetActiveDialogParent(),
                                                                                 rStyleSet,
                                                                                 aStr,
-                                                                                nResId);
+                                                                                nResId));
                         OSL_ENSURE(pDlg, "Dialog create fail!");
                         if ( pDlg->Execute() == RET_OK )
                         {
@@ -1717,7 +1716,6 @@ void ScDocShell::ExecutePageStyle( SfxViewShell& rCaller,
                             SetDocumentModified();
                             rReq.Done();
                         }
-                        delete pDlg;
                     }
                 }
             }
diff --git a/sc/source/ui/drawfunc/drawsh.cxx b/sc/source/ui/drawfunc/drawsh.cxx
index 6e4f62e..a7552d3 100644
--- a/sc/source/ui/drawfunc/drawsh.cxx
+++ b/sc/source/ui/drawfunc/drawsh.cxx
@@ -58,6 +58,7 @@
 #include <sfx2/viewsh.hxx>
 #include <com/sun/star/util/XModifiable.hpp>
 #include <com/sun/star/frame/XFrame.hpp>
+#include <boost/scoped_ptr.hpp>
 
 TYPEINIT1( ScDrawShell, SfxShell );
 
@@ -256,7 +257,7 @@ void ScDrawShell::ExecDrawAttr( SfxRequest& rReq )
                                 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
                                 if ( pFact )
                                 {
-                                    SfxAbstractTabDialog *pDlg = pFact->CreateCaptionDialog( pWin, pView );
+                                    boost::scoped_ptr<SfxAbstractTabDialog> pDlg(pFact->CreateCaptionDialog( pWin, pView ));
 
                                     const sal_uInt16* pRange = pDlg->GetInputRanges( *aNewAttr.GetPool() );
                                     SfxItemSet aCombSet( *aNewAttr.GetPool(), pRange );
@@ -270,8 +271,6 @@ void ScDrawShell::ExecDrawAttr( SfxRequest& rReq )
                                         pView->SetAttributes(*pDlg->GetOutputItemSet());
                                         pView->SetGeoAttrToMarked(*pDlg->GetOutputItemSet());
                                     }
-
-                                    delete pDlg;
                                 }
                             }
                             else
@@ -280,14 +279,13 @@ void ScDrawShell::ExecDrawAttr( SfxRequest& rReq )
                                 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
                                 if(pFact)
                                 {
-                                    SfxAbstractTabDialog* pDlg = pFact->CreateSvxTransformTabDialog( pWin, &aNewAttr,pView );
+                                    boost::scoped_ptr<SfxAbstractTabDialog> pDlg(pFact->CreateSvxTransformTabDialog( pWin, &aNewAttr,pView ));
                                     OSL_ENSURE(pDlg, "Dialog creation failed!");
                                     if (pDlg->Execute() == RET_OK)
                                     {
                                         rReq.Done(*(pDlg->GetOutputItemSet()));
                                         pView->SetGeoAttrToMarked(*pDlg->GetOutputItemSet());
                                     }
-                                    delete pDlg;
                                 }
                             }
                         }
@@ -331,7 +329,7 @@ void ScDrawShell::ExecuteMacroAssign( SdrObject* pObj, Window* pWin )
     }
 
     // create empty itemset for macro-dlg
-    SfxItemSet* pItemSet = new SfxItemSet(SFX_APP()->GetPool(), SID_ATTR_MACROITEM, SID_ATTR_MACROITEM, SID_EVENTCONFIG, SID_EVENTCONFIG, 0 );
+    boost::scoped_ptr<SfxItemSet> pItemSet(new SfxItemSet(SFX_APP()->GetPool(), SID_ATTR_MACROITEM, SID_ATTR_MACROITEM, SID_EVENTCONFIG, SID_EVENTCONFIG, 0 ));
     pItemSet->Put ( aItem, SID_ATTR_MACROITEM );
 
     SfxEventNamesItem aNamesItem(SID_EVENTCONFIG);
@@ -343,7 +341,7 @@ void ScDrawShell::ExecuteMacroAssign( SdrObject* pObj, Window* pWin )
         xFrame = GetViewShell()->GetViewFrame()->GetFrame().GetFrameInterface();
 
     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
-    SfxAbstractDialog* pMacroDlg = pFact->CreateSfxDialog( pWin, *pItemSet, xFrame, SID_EVENTCONFIG );
+    boost::scoped_ptr<SfxAbstractDialog> pMacroDlg(pFact->CreateSfxDialog( pWin, *pItemSet, xFrame, SID_EVENTCONFIG ));
     if ( pMacroDlg && pMacroDlg->Execute() == RET_OK )
     {
         const SfxItemSet* pOutSet = pMacroDlg->GetOutputItemSet();
@@ -370,9 +368,6 @@ void ScDrawShell::ExecuteMacroAssign( SdrObject* pObj, Window* pWin )
             lcl_setModified( GetObjectShell() );
         }
     }
-
-    delete pMacroDlg;
-    delete pItemSet;
 }
 
 void ScDrawShell::ExecuteLineDlg( SfxRequest& rReq, sal_uInt16 nTabPage )
@@ -391,11 +386,11 @@ void ScDrawShell::ExecuteLineDlg( SfxRequest& rReq, sal_uInt16 nTabPage )
 
     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     OSL_ENSURE(pFact, "Dialogdiet Factory fail!");
-    SfxAbstractTabDialog * pDlg = pFact->CreateSvxLineTabDialog( pViewData->GetDialogParent(),
+    boost::scoped_ptr<SfxAbstractTabDialog> pDlg(pFact->CreateSvxLineTabDialog( pViewData->GetDialogParent(),
                 &aNewAttr,
             pViewData->GetDocument()->GetDrawLayer(),
             pObj,
-            bHasMarked);
+            bHasMarked));
     OSL_ENSURE(pDlg, "Dialogdiet fail!");
     if ( nTabPage != 0xffff )
         pDlg->SetCurPageId( nTabPage );
@@ -410,8 +405,6 @@ void ScDrawShell::ExecuteLineDlg( SfxRequest& rReq, sal_uInt16 nTabPage )
         pView->InvalidateAttribs();
         rReq.Done();
     }
-
-    delete pDlg;
 }
 
 void ScDrawShell::ExecuteAreaDlg( SfxRequest& rReq, sal_uInt16 nTabPage )
@@ -425,9 +418,9 @@ void ScDrawShell::ExecuteAreaDlg( SfxRequest& rReq, sal_uInt16 nTabPage )
 
 
     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
-    AbstractSvxAreaTabDialog * pDlg = pFact->CreateSvxAreaTabDialog(
+    boost::scoped_ptr<AbstractSvxAreaTabDialog> pDlg(pFact->CreateSvxAreaTabDialog(
         pViewData->GetDialogParent(), &aNewAttr,
-        pViewData->GetDocument()->GetDrawLayer(), true);
+        pViewData->GetDocument()->GetDrawLayer(), true));
 
     if ( nTabPage != 0xffff )
         pDlg->SetCurPageId( nTabPage );
@@ -442,8 +435,6 @@ void ScDrawShell::ExecuteAreaDlg( SfxRequest& rReq, sal_uInt16 nTabPage )
         pView->InvalidateAttribs();
         rReq.Done();
     }
-
-    delete pDlg;
 }
 
 void ScDrawShell::ExecuteTextAttrDlg( SfxRequest& rReq, sal_uInt16 /* nTabPage */ )
@@ -456,7 +447,7 @@ void ScDrawShell::ExecuteTextAttrDlg( SfxRequest& rReq, sal_uInt16 /* nTabPage *
         pView->MergeAttrFromMarked( aNewAttr, false );
 
     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
-    SfxAbstractTabDialog *pDlg = pFact->CreateTextTabDialog( pViewData->GetDialogParent(), &aNewAttr, pView );
+    boost::scoped_ptr<SfxAbstractTabDialog> pDlg(pFact->CreateTextTabDialog( pViewData->GetDialogParent(), &aNewAttr, pView ));
 
     sal_uInt16 nResult = pDlg->Execute();
 
@@ -470,7 +461,6 @@ void ScDrawShell::ExecuteTextAttrDlg( SfxRequest& rReq, sal_uInt16 /* nTabPage *
         pView->InvalidateAttribs();
         rReq.Done();
     }
-    delete( pDlg );
 }
 
 void ScDrawShell::SetHlinkForObject( SdrObject* pObj, const OUString& rHlnk )
diff --git a/sc/source/ui/drawfunc/drawsh5.cxx b/sc/source/ui/drawfunc/drawsh5.cxx
index f1786bd..10644e4 100644
--- a/sc/source/ui/drawfunc/drawsh5.cxx
+++ b/sc/source/ui/drawfunc/drawsh5.cxx
@@ -55,6 +55,7 @@
 #include "drwlayer.hxx"
 #include "userdat.hxx"
 #include "postit.hxx"
+#include <boost/scoped_ptr.hpp>
 
 #include "sc.hrc"
 
@@ -490,7 +491,7 @@ void ScDrawShell::ExecDrawFunc( SfxRequest& rReq )
 
                         SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
                         OSL_ENSURE(pFact, "Dialogdiet fail!");
-                        AbstractSvxObjectNameDialog* pDlg = pFact->CreateSvxObjectNameDialog(NULL, aName);
+                        boost::scoped_ptr<AbstractSvxObjectNameDialog> pDlg(pFact->CreateSvxObjectNameDialog(NULL, aName));
                         OSL_ENSURE(pDlg, "Dialogdiet fail!");
 
                         pDlg->SetCheckNameHdl(LINK(this, ScDrawShell, NameObjectHdl));
@@ -539,8 +540,6 @@ void ScDrawShell::ExecDrawFunc( SfxRequest& rReq )
                             pDocSh->GetDocument()->SetChartListenerCollectionNeedsUpdate( true );
                             pDocSh->SetDrawModified();
                         }
-
-                        delete pDlg;
                     }
                 }
                 break;
@@ -561,7 +560,7 @@ void ScDrawShell::ExecDrawFunc( SfxRequest& rReq )
 
                         SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
                         OSL_ENSURE(pFact, "Dialogdiet fail!");
-                        AbstractSvxObjectTitleDescDialog* pDlg = pFact->CreateSvxObjectTitleDescDialog(NULL, aTitle, aDescription);
+                        boost::scoped_ptr<AbstractSvxObjectTitleDescDialog> pDlg(pFact->CreateSvxObjectTitleDescDialog(NULL, aTitle, aDescription));
                         OSL_ENSURE(pDlg, "Dialogdiet fail!");
 
                         if(RET_OK == pDlg->Execute())
@@ -578,8 +577,6 @@ void ScDrawShell::ExecDrawFunc( SfxRequest& rReq )
                             pDocSh->GetDocument()->SetChartListenerCollectionNeedsUpdate( true );
                             pDocSh->SetDrawModified();
                         }
-
-                        delete pDlg;
                     }
                 }
                 break;


More information about the Libreoffice-commits mailing list