diff options
author | Takeshi Abe <tabe@fixedpoint.jp> | 2014-05-11 01:36:27 +0900 |
---|---|---|
committer | Takeshi Abe <tabe@fixedpoint.jp> | 2014-05-11 01:38:14 +0900 |
commit | e62a3e875ac3437c6b0d08fa6e7e1d0b97141a7b (patch) | |
tree | 04f07ee7f5fa02b7126da12de4884476a0b58c8c /sc | |
parent | a647ff1f9297d272edd179c08799c0fe5d368c62 (diff) |
Avoid possible memory leaks in case of exceptions
Change-Id: I9cafee23bbf016024393550166aefdc782b488cb
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/ui/view/cellsh1.cxx | 49 | ||||
-rw-r--r-- | sc/source/ui/view/pivotsh.cxx | 6 | ||||
-rw-r--r-- | sc/source/ui/view/prevwsh.cxx | 6 |
3 files changed, 23 insertions, 38 deletions
diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx index e53be77d85b9..3cccca4debf1 100644 --- a/sc/source/ui/view/cellsh1.cxx +++ b/sc/source/ui/view/cellsh1.cxx @@ -205,11 +205,10 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq ) ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); OSL_ENSURE(pFact, "ScAbstractFactory create fail!"); - AbstractScInsertCellDlg* pDlg = pFact->CreateScInsertCellDlg( pTabViewShell->GetDialogParent(), RID_SCDLG_INSCELL, bTheFlag); + boost::scoped_ptr<AbstractScInsertCellDlg> pDlg(pFact->CreateScInsertCellDlg( pTabViewShell->GetDialogParent(), RID_SCDLG_INSCELL, bTheFlag)); OSL_ENSURE(pDlg, "Dialog create fail!"); if (pDlg->Execute() == RET_OK) eCmd = pDlg->GetInsCellCmd(); - delete pDlg; } } @@ -278,12 +277,11 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq ) ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); OSL_ENSURE(pFact, "ScAbstractFactory create fail!"); - AbstractScDeleteCellDlg* pDlg = pFact->CreateScDeleteCellDlg( pTabViewShell->GetDialogParent(), bTheFlag ); + boost::scoped_ptr<AbstractScDeleteCellDlg> pDlg(pFact->CreateScDeleteCellDlg( pTabViewShell->GetDialogParent(), bTheFlag )); OSL_ENSURE(pDlg, "Dialog create fail!"); if (pDlg->Execute() == RET_OK) eCmd = pDlg->GetDelCellCmd(); - delete pDlg; } } @@ -363,7 +361,7 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq ) ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); OSL_ENSURE(pFact, "ScAbstractFactory create fail!"); - AbstractScDeleteContentsDlg* pDlg = pFact->CreateScDeleteContentsDlg(pTabViewShell->GetDialogParent()); + boost::scoped_ptr<AbstractScDeleteContentsDlg> pDlg(pFact->CreateScDeleteContentsDlg(pTabViewShell->GetDialogParent())); OSL_ENSURE(pDlg, "Dialog create fail!"); ScDocument* pDoc = GetViewData()->GetDocument(); SCTAB nTab = GetViewData()->GetTabNo(); @@ -373,7 +371,6 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq ) { nFlags = pDlg->GetDelContentsCmdBits(); } - delete pDlg; } else pTabViewShell->ErrorMessage(aTester.GetMessageId()); @@ -473,9 +470,9 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq ) ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); OSL_ENSURE(pFact, "ScAbstractFactory create fail!"); - AbstractScInsertContentsDlg* pDlg = pFact->CreateScInsertContentsDlg( pTabViewShell->GetDialogParent(), + boost::scoped_ptr<AbstractScInsertContentsDlg> pDlg(pFact->CreateScInsertContentsDlg( pTabViewShell->GetDialogParent(), 0, /* nCheckDefaults */ - &ScGlobal::GetRscString(STR_FILL_TAB)); + &ScGlobal::GetRscString(STR_FILL_TAB))); OSL_ENSURE(pDlg, "Dialog create fail!"); pDlg->SetFillMode(true); @@ -487,7 +484,6 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq ) bAsLink = pDlg->IsLink(); // there is no MoveMode with fill tabs } - delete pDlg; } if( nFlags != IDF_NONE ) @@ -706,11 +702,11 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq ) ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); OSL_ENSURE(pFact, "ScAbstractFactory create fail!"); - AbstractScFillSeriesDlg* pDlg = pFact->CreateScFillSeriesDlg( pTabViewShell->GetDialogParent(), + boost::scoped_ptr<AbstractScFillSeriesDlg> pDlg(pFact->CreateScFillSeriesDlg( pTabViewShell->GetDialogParent(), *pDoc, eFillDir, eFillCmd, eFillDateCmd, aStartStr, fIncVal, fMaxVal, - nPossDir); + nPossDir)); OSL_ENSURE(pDlg, "Dialog create fail!"); if ( nStartCol != nEndCol && nStartRow != nEndRow ) @@ -735,7 +731,6 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq ) fMaxVal = pDlg->GetMax(); bDoIt = true; } - delete pDlg; } if( bDoIt ) @@ -1123,13 +1118,12 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq ) ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); OSL_ENSURE(pFact, "ScAbstractFactory create fail!"); - AbstractScGroupDlg* pDlg = pFact->CreateAbstractScGroupDlg(pTabViewShell->GetDialogParent(), false); + boost::scoped_ptr<AbstractScGroupDlg> pDlg(pFact->CreateAbstractScGroupDlg(pTabViewShell->GetDialogParent(), false)); OSL_ENSURE(pDlg, "Dialog create fail!"); if ( pDlg->Execute() == RET_OK ) bColumns = pDlg->GetColsChecked(); else bOk = false; - delete pDlg; } } if (bOk) @@ -1183,13 +1177,12 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq ) ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); OSL_ENSURE(pFact, "ScAbstractFactory create fail!"); - AbstractScGroupDlg* pDlg = pFact->CreateAbstractScGroupDlg(pTabViewShell->GetDialogParent(), true); + boost::scoped_ptr<AbstractScGroupDlg> pDlg(pFact->CreateAbstractScGroupDlg(pTabViewShell->GetDialogParent(), true)); OSL_ENSURE(pDlg, "Dialog create fail!"); if ( pDlg->Execute() == RET_OK ) bColumns = pDlg->GetColsChecked(); else bOk = false; - delete pDlg; } else if ( bColPoss ) bColumns = true; @@ -1348,7 +1341,7 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq ) ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); OSL_ENSURE(pFact, "ScAbstractFactory create fail!"); - AbstractScInsertContentsDlg* pDlg = pFact->CreateScInsertContentsDlg(pTabViewShell->GetDialogParent()); + boost::scoped_ptr<AbstractScInsertContentsDlg> pDlg(pFact->CreateScInsertContentsDlg(pTabViewShell->GetDialogParent())); OSL_ENSURE(pDlg, "Dialog create fail!"); pDlg->SetOtherDoc( bOtherDoc ); // if ChangeTrack MoveMode disable @@ -1422,7 +1415,6 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq ) bAsLink = pDlg->IsLink(); eMoveMode = pDlg->GetMoveMode(); } - delete pDlg; } else pTabViewShell->ErrorMessage(aTester.GetMessageId()); @@ -1549,7 +1541,7 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq ) if ( nFormatCount ) { SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); - SfxAbstractPasteDialog* pDlg = pFact->CreatePasteDialog( pTabViewShell->GetDialogParent() ); + boost::scoped_ptr<SfxAbstractPasteDialog> pDlg(pFact->CreatePasteDialog( pTabViewShell->GetDialogParent() )); if ( pDlg ) { for (sal_uInt16 i=0; i<nFormatCount; i++) @@ -1583,8 +1575,6 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq ) rReq.SetReturnValue(SfxInt16Item(nSlot, 0)); // 0 = fail rReq.Ignore(); } - - delete pDlg; } } else @@ -1782,7 +1772,7 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq ) ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); OSL_ENSURE(pFact, "ScAbstractFactory create fail!"); - AbstractScNameCreateDlg* pDlg = pFact->CreateScNameCreateDlg(pTabViewShell->GetDialogParent(), nFlags); + boost::scoped_ptr<AbstractScNameCreateDlg> pDlg(pFact->CreateScNameCreateDlg(pTabViewShell->GetDialogParent(), nFlags)); OSL_ENSURE(pDlg, "Dialog create fail!"); if( pDlg->Execute() ) @@ -1791,7 +1781,6 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq ) pTabViewShell->CreateNames(nFlags); rReq.Done(); } - delete pDlg; } break; @@ -2089,7 +2078,7 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq ) ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); OSL_ENSURE(pFact, "ScAbstractFactory create fail!"); - AbstractScNamePasteDlg* pDlg = pFact->CreateScNamePasteDlg( pTabViewShell->GetDialogParent(), GetViewData()->GetDocShell() ); + boost::scoped_ptr<AbstractScNamePasteDlg> pDlg(pFact->CreateScNamePasteDlg( pTabViewShell->GetDialogParent(), GetViewData()->GetDocShell() )); OSL_ENSURE(pDlg, "Dialog create fail!"); switch( pDlg->Execute() ) { @@ -2119,7 +2108,6 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq ) } break; } - delete pDlg; } break; @@ -2294,8 +2282,8 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq ) aSet.Put( SfxBoolItem( FN_PARAM_1, false ) ); aSet.Put( SvxFontItem( aCurFont.GetFamily(), aCurFont.GetName(), aCurFont.GetStyleName(), aCurFont.GetPitch(), aCurFont.GetCharSet(), GetPool().GetWhich(SID_ATTR_CHAR_FONT) ) ); - SfxAbstractDialog* pDlg = pFact->CreateSfxDialog( pTabViewShell->GetDialogParent(), aSet, - pTabViewShell->GetViewFrame()->GetFrame().GetFrameInterface(), RID_SVXDLG_CHARMAP ); + boost::scoped_ptr<SfxAbstractDialog> pDlg(pFact->CreateSfxDialog( pTabViewShell->GetDialogParent(), aSet, + pTabViewShell->GetViewFrame()->GetFrame().GetFrameInterface(), RID_SVXDLG_CHARMAP )); if ( pDlg->Execute() == RET_OK ) { @@ -2313,7 +2301,6 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq ) rReq.Done(); } } - delete pDlg; } break; @@ -2718,7 +2705,7 @@ void ScCellShell::ExecuteSubtotals(SfxRequest& rReq) return; } - SfxAbstractTabDialog * pDlg = NULL; + boost::scoped_ptr<SfxAbstractTabDialog> pDlg; ScSubTotalParam aSubTotalParam; SfxItemSet aArgSet( GetPool(), SCITEM_SUBTDATA, SCITEM_SUBTDATA ); @@ -2741,7 +2728,7 @@ void ScCellShell::ExecuteSubtotals(SfxRequest& rReq) ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); assert(pFact); //"ScAbstractFactory create fail - pDlg = pFact->CreateScSubTotalDlg(pTabViewShell->GetDialogParent(), &aArgSet); + pDlg.reset(pFact->CreateScSubTotalDlg(pTabViewShell->GetDialogParent(), &aArgSet)); assert(pDlg); // "Dialog create fail pDlg->SetCurPageId(1); @@ -2774,8 +2761,6 @@ void ScCellShell::ExecuteSubtotals(SfxRequest& rReq) } else GetViewData()->GetDocShell()->CancelAutoDBRange(); - - delete pDlg; } void ScCellShell::ExecuteFillSingleEdit() diff --git a/sc/source/ui/view/pivotsh.cxx b/sc/source/ui/view/pivotsh.cxx index ee9fede3da41..ff4b004989ed 100644 --- a/sc/source/ui/view/pivotsh.cxx +++ b/sc/source/ui/view/pivotsh.cxx @@ -41,6 +41,7 @@ #define ScPivotShell #include "scslots.hxx" +#include <boost/scoped_ptr.hpp> TYPEINIT1( ScPivotShell, SfxShell ); @@ -107,8 +108,8 @@ void ScPivotShell::Execute( SfxRequest& rReq ) ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); OSL_ENSURE(pFact, "ScAbstractFactory create fail!"); - AbstractScPivotFilterDlg* pDlg = pFact->CreateScPivotFilterDlg( - pViewShell->GetDialogParent(), aArgSet, nSrcTab); + boost::scoped_ptr<AbstractScPivotFilterDlg> pDlg(pFact->CreateScPivotFilterDlg( + pViewShell->GetDialogParent(), aArgSet, nSrcTab)); OSL_ENSURE(pDlg, "Dialog create fail!"); if( pDlg->Execute() == RET_OK ) @@ -126,7 +127,6 @@ void ScPivotShell::Execute( SfxRequest& rReq ) aFunc.DataPilotUpdate( pDPObj, &aNewObj, true, false ); pViewData->GetView()->CursorPosChanged(); // shells may be switched } - delete pDlg; } } break; diff --git a/sc/source/ui/view/prevwsh.cxx b/sc/source/ui/view/prevwsh.cxx index 64af102876be..18eb3a79fa0c 100644 --- a/sc/source/ui/view/prevwsh.cxx +++ b/sc/source/ui/view/prevwsh.cxx @@ -81,6 +81,8 @@ using namespace com::sun::star; #define ScPreviewShell #include "scslots.hxx" +#include <boost/scoped_ptr.hpp> + TYPEINIT1( ScPreviewShell, SfxViewShell ); SFX_IMPL_INTERFACE(ScPreviewShell, SfxViewShell, ScResId(SCSTR_PREVIEWSHELL)) @@ -651,7 +653,7 @@ void ScPreviewShell::Execute( SfxRequest& rReq ) SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); if(pFact) { - AbstractSvxZoomDialog* pDlg = pFact->CreateSvxZoomDialog(NULL, aSet); + boost::scoped_ptr<AbstractSvxZoomDialog> pDlg(pFact->CreateSvxZoomDialog(NULL, aSet)); OSL_ENSURE(pDlg, "Dialogdiet fail!"); pDlg->SetLimits( 20, 400 ); pDlg->HideButton( ZOOMBTN_OPTIMAL ); @@ -666,8 +668,6 @@ void ScPreviewShell::Execute( SfxRequest& rReq ) eZoom = rZoomItem.GetType(); nZoom = rZoomItem.GetValue(); } - - delete pDlg; } } |