From b32ee047312a49c13a247aa57485fad128f13317 Mon Sep 17 00:00:00 2001 From: Takeshi Abe Date: Sat, 31 May 2014 22:29:14 +0900 Subject: Avoid possible memory leaks in case of exceptions Change-Id: I1988d2766d8bdeb5f8a22a5673dcff9b898dd637 --- sw/source/uibase/wrtsh/select.cxx | 11 +++++------ sw/source/uibase/wrtsh/wrtsh1.cxx | 7 +++---- sw/source/uibase/wrtsh/wrtsh2.cxx | 11 ++++++----- 3 files changed, 14 insertions(+), 15 deletions(-) (limited to 'sw/source/uibase') diff --git a/sw/source/uibase/wrtsh/select.cxx b/sw/source/uibase/wrtsh/select.cxx index 76a4c2eb8d66..29fa6c402aca 100644 --- a/sw/source/uibase/wrtsh/select.cxx +++ b/sw/source/uibase/wrtsh/select.cxx @@ -39,6 +39,7 @@ #include #include #include +#include namespace com { namespace sun { namespace star { namespace util { struct SearchOptions; @@ -128,8 +129,8 @@ long SwWrtShell::SelAll() LeaveBlockMode(); SwMvContext aMvContext(this); bool bMoveTable = false; - SwPosition *pStartPos = 0; - SwPosition *pEndPos = 0; + boost::scoped_ptr pStartPos; + boost::scoped_ptr pEndPos; SwShellCrsr* pTmpCrsr = 0; if( !HasWholeTabSelection() ) { @@ -138,8 +139,8 @@ long SwWrtShell::SelAll() pTmpCrsr = getShellCrsr( false ); if( pTmpCrsr ) { - pStartPos = new SwPosition( *pTmpCrsr->GetPoint() ); - pEndPos = new SwPosition( *pTmpCrsr->GetMark() ); + pStartPos.reset(new SwPosition( *pTmpCrsr->GetPoint() )); + pEndPos.reset(new SwPosition( *pTmpCrsr->GetMark() )); } Push(); bool bIsFullSel = !MoveSection( fnSectionCurr, fnSectionStart); @@ -187,8 +188,6 @@ long SwWrtShell::SelAll() *pEndPos == *pTmpCrsr->GetPoint() ) ) && !bStartsWithTable) SwCrsrShell::SttEndDoc(false); } - delete pStartPos; - delete pEndPos; } } EndSelect(); diff --git a/sw/source/uibase/wrtsh/wrtsh1.cxx b/sw/source/uibase/wrtsh/wrtsh1.cxx index b1893be9f54c..dbd8c055eec9 100644 --- a/sw/source/uibase/wrtsh/wrtsh1.cxx +++ b/sw/source/uibase/wrtsh/wrtsh1.cxx @@ -102,6 +102,7 @@ #include "PostItMgr.hxx" #include +#include using namespace sw::mark; using namespace com::sun::star; @@ -371,8 +372,8 @@ void SwWrtShell::InsertObject( const svt::EmbeddedObjectRef& xRef, SvGlobalName OString aCmd(".uno:"); aCmd += pSlot->GetUnoName(); SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); - SfxAbstractInsertObjectDialog* pDlg = - pFact->CreateInsertObjectDialog( GetWin(), OStringToOUString( aCmd, RTL_TEXTENCODING_UTF8 ), xStor, &aServerList ); + boost::scoped_ptr pDlg( + pFact->CreateInsertObjectDialog( GetWin(), OStringToOUString( aCmd, RTL_TEXTENCODING_UTF8 ), xStor, &aServerList )); if ( pDlg ) { pDlg->Execute(); @@ -383,8 +384,6 @@ void SwWrtShell::InsertObject( const svt::EmbeddedObjectRef& xRef, SvGlobalName xIconMetaFile.is() ? embed::Aspects::MSOLE_ICON : embed::Aspects::MSOLE_CONTENT ); if ( xIconMetaFile.is() ) xObj.SetGraphicStream( xIconMetaFile, aIconMediaType ); - - DELETEZ( pDlg ); } break; diff --git a/sw/source/uibase/wrtsh/wrtsh2.cxx b/sw/source/uibase/wrtsh/wrtsh2.cxx index ae1d19091d7d..e0cf20bda04a 100644 --- a/sw/source/uibase/wrtsh/wrtsh2.cxx +++ b/sw/source/uibase/wrtsh/wrtsh2.cxx @@ -63,6 +63,7 @@ #include #include +#include void SwWrtShell::Insert(SwField &rFld) { @@ -192,13 +193,13 @@ bool SwWrtShell::StartInputFldDlg( SwField* pFld, bool bNextButton, SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); OSL_ENSURE(pFact, "Dialogdiet fail!"); - AbstractFldInputDlg* pDlg = pFact->CreateFldInputDlg(pParentWin, *this, pFld, bNextButton); + boost::scoped_ptr pDlg(pFact->CreateFldInputDlg(pParentWin, *this, pFld, bNextButton)); OSL_ENSURE(pDlg, "Dialogdiet fail!"); if(pWindowState && !pWindowState->isEmpty()) pDlg->SetWindowState(*pWindowState); // Register for possible input field deletion while dialog is open - FieldDeletionModify aModify(pDlg); + FieldDeletionModify aModify(pDlg.get()); GetDoc()->GetUnoCallBack()->Add(&aModify); bool bRet = RET_CANCEL == pDlg->Execute(); @@ -209,7 +210,7 @@ bool SwWrtShell::StartInputFldDlg( SwField* pFld, bool bNextButton, if(pWindowState) *pWindowState = pDlg->GetWindowState(); - delete pDlg; + pDlg.reset(); GetWin()->Update(); return bRet; } @@ -219,14 +220,14 @@ bool SwWrtShell::StartDropDownFldDlg(SwField* pFld, bool bNextButton, OString* p SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!"); - AbstractDropDownFieldDialog* pDlg = pFact->CreateDropDownFieldDialog(NULL, *this, pFld, bNextButton); + boost::scoped_ptr pDlg(pFact->CreateDropDownFieldDialog(NULL, *this, pFld, bNextButton)); OSL_ENSURE(pDlg, "Dialogdiet fail!"); if(pWindowState && !pWindowState->isEmpty()) pDlg->SetWindowState(*pWindowState); sal_uInt16 nRet = pDlg->Execute(); if(pWindowState) *pWindowState = pDlg->GetWindowState(); - delete pDlg; + pDlg.reset(); bool bRet = RET_CANCEL == nRet; GetWin()->Update(); if(RET_YES == nRet) -- cgit v1.2.3