From c260abe39e0063a2e5ba4e0d22ff8a5ccd468c23 Mon Sep 17 00:00:00 2001 From: Takeshi Abe Date: Sat, 21 Jun 2014 22:54:28 +0900 Subject: Avoid possible memory leaks in case of exceptions Change-Id: I27a0c3639c346720df471ffa3940783565c47f7d --- svx/source/dialog/imapdlg.cxx | 9 ++++----- svx/source/dialog/imapwnd.cxx | 10 ++++------ svx/source/dialog/measctrl.cxx | 12 ++++++------ svx/source/dialog/srchdlg.cxx | 23 ++++++++++------------- svx/source/fmcomp/fmgridcl.cxx | 4 ++-- sw/source/uibase/wrtsh/wrtsh2.cxx | 10 +++++----- 6 files changed, 31 insertions(+), 37 deletions(-) diff --git a/svx/source/dialog/imapdlg.cxx b/svx/source/dialog/imapdlg.cxx index f06240786895..4b6fa84cf3a9 100644 --- a/svx/source/dialog/imapdlg.cxx +++ b/svx/source/dialog/imapdlg.cxx @@ -54,6 +54,7 @@ #include #include #include "dlgunit.hxx" +#include #define SELF_TARGET "_self" #define IMAP_ALL_FILTER OUString("") @@ -484,7 +485,7 @@ void SvxIMapDlg::DoOpen() { INetURLObject aURL( aDlg.GetPath() ); DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" ); - SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ ); + boost::scoped_ptr pIStm(::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ )); if( pIStm ) { @@ -497,8 +498,6 @@ void SvxIMapDlg::DoOpen() } else pIMapWnd->SetImageMap( aLoadIMap ); - - delete pIStm; } pIMapWnd->Invalidate(); @@ -561,7 +560,7 @@ bool SvxIMapDlg::DoSave() if( aURL.getExtension().isEmpty() ) aURL.setExtension( aExt ); - SvStream* pOStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE | STREAM_TRUNC ); + boost::scoped_ptr pOStm(::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE | STREAM_TRUNC )); if( pOStm ) { pIMapWnd->GetImageMap().Write( *pOStm, nFormat, "" ); @@ -569,7 +568,7 @@ bool SvxIMapDlg::DoSave() if( pOStm->GetError() ) ErrorHandler::HandleError( ERRCODE_IO_GENERAL ); - delete pOStm; + pOStm.reset(); pModel->SetChanged( bChanged ); bRet = true; } diff --git a/svx/source/dialog/imapwnd.cxx b/svx/source/dialog/imapwnd.cxx index e591947ae941..05e0e8be55a8 100644 --- a/svx/source/dialog/imapwnd.cxx +++ b/svx/source/dialog/imapwnd.cxx @@ -48,6 +48,7 @@ #include #include #include +#include using ::com::sun::star::frame::XFrame; using ::com::sun::star::uno::Reference; @@ -643,7 +644,7 @@ void IMapWindow::DoMacroAssign() aSet.Put( aMacroItem, SID_ATTR_MACROITEM ); SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); - SfxAbstractDialog* pMacroDlg = pFact->CreateSfxDialog( this, aSet, mxDocumentFrame, SID_EVENTCONFIG ); + boost::scoped_ptr pMacroDlg(pFact->CreateSfxDialog( this, aSet, mxDocumentFrame, SID_EVENTCONFIG )); if ( pMacroDlg && pMacroDlg->Execute() == RET_OK ) { @@ -652,8 +653,6 @@ void IMapWindow::DoMacroAssign() pModel->SetChanged( true ); UpdateInfo( false ); } - - delete pMacroDlg; } } @@ -667,8 +666,8 @@ void IMapWindow::DoPropertyDialog() SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); if(pFact) { - AbstractURLDlg* aDlg = pFact->CreateURLDialog( this, pIMapObj->GetURL(), pIMapObj->GetAltText(), pIMapObj->GetDesc(), - pIMapObj->GetTarget(), pIMapObj->GetName(), aTargetList ); + boost::scoped_ptr aDlg(pFact->CreateURLDialog( this, pIMapObj->GetURL(), pIMapObj->GetAltText(), pIMapObj->GetDesc(), + pIMapObj->GetTarget(), pIMapObj->GetName(), aTargetList )); DBG_ASSERT(aDlg, "Dialogdiet fail!"); if ( aDlg->Execute() == RET_OK ) { @@ -690,7 +689,6 @@ void IMapWindow::DoPropertyDialog() pModel->SetChanged( true ); UpdateInfo( true ); } - delete aDlg; } } } diff --git a/svx/source/dialog/measctrl.cxx b/svx/source/dialog/measctrl.cxx index 5d2910f98145..29b2c4bf9879 100644 --- a/svx/source/dialog/measctrl.cxx +++ b/svx/source/dialog/measctrl.cxx @@ -25,6 +25,7 @@ #include "svx/dlgutil.hxx" #include #include +#include SvxXMeasurePreview::SvxXMeasurePreview( Window* pParent, WinBits nStyle) : Control(pParent, nStyle) @@ -110,21 +111,21 @@ void SvxXMeasurePreview::MouseButtonDown( const MouseEvent& rMEvt ) MapMode aMapMode = GetMapMode(); Fraction aXFrac = aMapMode.GetScaleX(); Fraction aYFrac = aMapMode.GetScaleY(); - Fraction* pMultFrac; + boost::scoped_ptr pMultFrac; if( bZoomIn ) { if( bCtrl ) - pMultFrac = new Fraction( 3, 2 ); + pMultFrac.reset(new Fraction( 3, 2 )); else - pMultFrac = new Fraction( 11, 10 ); + pMultFrac.reset(new Fraction( 11, 10 )); } else { if( bCtrl ) - pMultFrac = new Fraction( 2, 3 ); + pMultFrac.reset(new Fraction( 2, 3 )); else - pMultFrac = new Fraction( 10, 11 ); + pMultFrac.reset(new Fraction( 10, 11 )); } aXFrac *= *pMultFrac; @@ -149,7 +150,6 @@ void SvxXMeasurePreview::MouseButtonDown( const MouseEvent& rMEvt ) Invalidate(); } - delete pMultFrac; } } diff --git a/svx/source/dialog/srchdlg.cxx b/svx/source/dialog/srchdlg.cxx index 37f7de03079d..6a6cb82eea9c 100644 --- a/svx/source/dialog/srchdlg.cxx +++ b/svx/source/dialog/srchdlg.cxx @@ -67,6 +67,8 @@ #include #include #include +#include +#include using namespace com::sun::star::i18n; using namespace com::sun::star::uno; @@ -1285,11 +1287,11 @@ IMPL_LINK( SvxSearchDialog, CommandHdl_Impl, Button *, pBtn ) SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); if(pFact) { - AbstractSvxSearchSimilarityDialog* pDlg = pFact->CreateSvxSearchSimilarityDialog( this, + boost::scoped_ptr pDlg(pFact->CreateSvxSearchSimilarityDialog( this, pSearchItem->IsLEVRelaxed(), pSearchItem->GetLEVOther(), pSearchItem->GetLEVShorter(), - pSearchItem->GetLEVLonger() ); + pSearchItem->GetLEVLonger() )); DBG_ASSERT(pDlg, "Dialogdiet fail!"); if ( pDlg && pDlg->Execute() == RET_OK ) { @@ -1299,7 +1301,6 @@ IMPL_LINK( SvxSearchDialog, CommandHdl_Impl, Button *, pBtn ) pSearchItem->SetLEVLonger( pDlg->GetLonger() ); SaveToModule_Impl(); } - delete pDlg; } } else if (pBtn == m_pJapOptionsBtn) @@ -1309,8 +1310,8 @@ IMPL_LINK( SvxSearchDialog, CommandHdl_Impl, Button *, pBtn ) SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); if(pFact) { - AbstractSvxJSearchOptionsDialog* aDlg = pFact->CreateSvxJSearchOptionsDialog( this, aSet, - pSearchItem->GetTransliterationFlags() ); + boost::scoped_ptr aDlg(pFact->CreateSvxJSearchOptionsDialog( this, aSet, + pSearchItem->GetTransliterationFlags() )); DBG_ASSERT(aDlg, "Dialogdiet fail!"); int nRet = aDlg->Execute(); if (RET_OK == nRet) //! true only if FillItemSet of SvxJSearchOptionsPage returns true @@ -1319,7 +1320,6 @@ IMPL_LINK( SvxSearchDialog, CommandHdl_Impl, Button *, pBtn ) pSearchItem->SetTransliterationFlags( nFlags ); ApplyTransliterationFlags_Impl( nFlags ); } - delete aDlg; } } else if (pBtn == m_pSearchComponent1PB || pBtn == m_pSearchComponent2PB) @@ -1850,7 +1850,7 @@ IMPL_LINK_NOARG(SvxSearchDialog, FormatHdl_Impl) while( *pTmp ) pTmp++; nCnt = pTmp - pPtr + 7; - sal_uInt16* pWhRanges = new sal_uInt16[nCnt]; + boost::scoped_array pWhRanges(new sal_uInt16[nCnt]); sal_uInt16 nPos = 0; while( *pPtr ) @@ -1868,7 +1868,7 @@ IMPL_LINK_NOARG(SvxSearchDialog, FormatHdl_Impl) pWhRanges[nPos++] = SID_PARA_BACKGRND_DESTINATION; pWhRanges[nPos] = 0; SfxItemPool& rPool = pSh->GetPool(); - SfxItemSet aSet( rPool, pWhRanges ); + SfxItemSet aSet( rPool, pWhRanges.get() ); OUString aTxt; aSet.InvalidateAllItems(); @@ -1893,7 +1893,7 @@ IMPL_LINK_NOARG(SvxSearchDialog, FormatHdl_Impl) SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); if(pFact) { - SfxAbstractTabDialog* pDlg = pFact->CreateTabItemDialog(this, aSet); + boost::scoped_ptr pDlg(pFact->CreateTabItemDialog(this, aSet)); DBG_ASSERT(pDlg, "Dialogdiet fail!"); aTxt = pDlg->GetText() + aTxt; pDlg->SetText( aTxt ); @@ -1922,9 +1922,7 @@ IMPL_LINK_NOARG(SvxSearchDialog, FormatHdl_Impl) PaintAttrText_Impl(); // Set AttributText in GroupBox } - delete pDlg; } - delete[] pWhRanges; return 0; } @@ -1979,10 +1977,9 @@ IMPL_LINK_NOARG(SvxSearchDialog, AttributeHdl_Impl) SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); if(pFact) { - VclAbstractDialog* pDlg = pFact->CreateSvxSearchAttributeDialog( this, *pSearchList, pImpl->pRanges ); + boost::scoped_ptr pDlg(pFact->CreateSvxSearchAttributeDialog( this, *pSearchList, pImpl->pRanges )); DBG_ASSERT(pDlg, "Dialogdiet fail!"); pDlg->Execute(); - delete pDlg; } PaintAttrText_Impl(); return 0; diff --git a/svx/source/fmcomp/fmgridcl.cxx b/svx/source/fmcomp/fmgridcl.cxx index 7f74abd738dd..3139fd2a0184 100644 --- a/svx/source/fmcomp/fmgridcl.cxx +++ b/svx/source/fmcomp/fmgridcl.cxx @@ -72,6 +72,7 @@ #include #include +#include using namespace ::com::sun::star::uno; using namespace ::com::sun::star::view; @@ -859,11 +860,10 @@ void FmGridHeader::PostExecuteColumnContextMenu(sal_uInt16 nColId, const PopupMe SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); if(pFact) { - AbstractFmShowColsDialog* pDlg = pFact->CreateFmShowColsDialog(NULL); + boost::scoped_ptr pDlg(pFact->CreateFmShowColsDialog(NULL)); DBG_ASSERT(pDlg, "Dialogdiet fail!"); pDlg->SetColumns(xCols); pDlg->Execute(); - delete pDlg; } } diff --git a/sw/source/uibase/wrtsh/wrtsh2.cxx b/sw/source/uibase/wrtsh/wrtsh2.cxx index 1abb58135cb4..36d2321ed5fc 100644 --- a/sw/source/uibase/wrtsh/wrtsh2.cxx +++ b/sw/source/uibase/wrtsh/wrtsh2.cxx @@ -78,7 +78,7 @@ void SwWrtShell::Insert(SwField &rFld) StartUndo(UNDO_INSERT, &aRewriter); bool bDeleted = false; - const SwPaM* pAnnotationTextRange = NULL; + boost::scoped_ptr pAnnotationTextRange; if ( HasSelection() ) { if ( rFld.GetTyp()->Which() == RES_POSTITFLD ) @@ -96,13 +96,13 @@ void SwWrtShell::Insert(SwField &rFld) EndPara(); } const SwPosition rEndPos( *GetCurrentShellCursor().GetPoint() ); - pAnnotationTextRange = new SwPaM( rStartPos, rEndPos ); + pAnnotationTextRange.reset(new SwPaM( rStartPos, rEndPos )); } else { NormalizePam( false ); const SwPaM& rCurrPaM = GetCurrentShellCursor(); - pAnnotationTextRange = new SwPaM( *rCurrPaM.GetPoint(), *rCurrPaM.GetMark() ); + pAnnotationTextRange.reset(new SwPaM( *rCurrPaM.GetPoint(), *rCurrPaM.GetMark() )); ClearMark(); } } @@ -114,14 +114,14 @@ void SwWrtShell::Insert(SwField &rFld) SwEditShell::Insert2(rFld, bDeleted); - if ( pAnnotationTextRange != NULL ) + if ( pAnnotationTextRange ) { if ( GetDoc() != NULL ) { IDocumentMarkAccess* pMarksAccess = GetDoc()->getIDocumentMarkAccess(); pMarksAccess->makeAnnotationMark( *pAnnotationTextRange, ::rtl::OUString() ); } - delete pAnnotationTextRange; + pAnnotationTextRange.reset(); } EndUndo(); -- cgit