Avoid possible memory leaks in case of exceptions

Change-Id: Icc073be041ae0b0c690e869a0edaff3515d1d601
This commit is contained in:
Takeshi Abe
2014-08-25 10:22:59 +09:00
parent 49feed98a1
commit 32ce5ae15a
5 changed files with 15 additions and 21 deletions

View File

@@ -72,6 +72,7 @@
#include <map> #include <map>
#include <vector> #include <vector>
#include <boost/scoped_ptr.hpp>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
using namespace ::com::sun::star; using namespace ::com::sun::star;
@@ -488,11 +489,9 @@ IMPL_LINK_NOARG(ExtBoxWithBtns_Impl, HandleOptionsBtn)
if ( pFact ) if ( pFact )
{ {
OUString sExtensionId = GetEntryData( nActive )->m_xPackage->getIdentifier().Value; OUString sExtensionId = GetEntryData( nActive )->m_xPackage->getIdentifier().Value;
VclAbstractDialog* pDlg = pFact->CreateOptionsDialog( this, sExtensionId, OUString() ); boost::scoped_ptr<VclAbstractDialog> pDlg(pFact->CreateOptionsDialog( this, sExtensionId, OUString() ));
pDlg->Execute(); pDlg->Execute();
delete pDlg;
} }
} }

View File

@@ -191,13 +191,12 @@ EditPaM ImpEditEngine::ReadHTML( SvStream& rInput, const OUString& rBaseURL, Edi
EditPaM ImpEditEngine::ReadBin( SvStream& rInput, EditSelection aSel ) EditPaM ImpEditEngine::ReadBin( SvStream& rInput, EditSelection aSel )
{ {
// Simply abuse a temporary text object ... // Simply abuse a temporary text object ...
EditTextObject* pObj = EditTextObject::Create( rInput, NULL ); boost::scoped_ptr<EditTextObject> pObj(EditTextObject::Create( rInput, NULL ));
EditPaM aLastPaM = aSel.Max(); EditPaM aLastPaM = aSel.Max();
if ( pObj ) if ( pObj )
aLastPaM = InsertText( *pObj, aSel ).Max(); aLastPaM = InsertText( *pObj, aSel ).Max();
delete pObj;
return aLastPaM; return aLastPaM;
} }
@@ -2499,7 +2498,7 @@ EESpellState ImpEditEngine::StartThesaurus( EditView* pEditView )
return EE_SPELL_ERRORFOUND; return EE_SPELL_ERRORFOUND;
EditAbstractDialogFactory* pFact = EditAbstractDialogFactory::Create(); EditAbstractDialogFactory* pFact = EditAbstractDialogFactory::Create();
AbstractThesaurusDialog* pDlg = pFact->CreateThesaurusDialog( pEditView->GetWindow(), xThes, aWord, GetLanguage( aCurSel.Max() ) ); boost::scoped_ptr<AbstractThesaurusDialog> pDlg(pFact->CreateThesaurusDialog( pEditView->GetWindow(), xThes, aWord, GetLanguage( aCurSel.Max() ) ));
if ( pDlg->Execute() == RET_OK ) if ( pDlg->Execute() == RET_OK )
{ {
// Replace Word... // Replace Word...
@@ -2510,7 +2509,6 @@ EESpellState ImpEditEngine::StartThesaurus( EditView* pEditView )
pEditView->ShowCursor( true, false ); pEditView->ShowCursor( true, false );
} }
delete pDlg;
return EE_SPELL_OK; return EE_SPELL_OK;
} }

View File

@@ -39,6 +39,7 @@
#include <editeng/editrids.hrc> #include <editeng/editrids.hrc>
#include <editeng/editids.hrc> #include <editeng/editids.hrc>
#include <editeng/editerr.hxx> #include <editeng/editerr.hxx>
#include <boost/scoped_ptr.hpp>
#define WAIT_ON() if(pWin != NULL) { pWin->EnterWait(); } #define WAIT_ON() if(pWin != NULL) { pWin->EnterWait(); }
@@ -322,13 +323,12 @@ void SvxSpellWrapper::StartThesaurus( const OUString &rWord, sal_uInt16 nLanguag
WAIT_ON(); // while looking up for initial word WAIT_ON(); // while looking up for initial word
EditAbstractDialogFactory* pFact = EditAbstractDialogFactory::Create(); EditAbstractDialogFactory* pFact = EditAbstractDialogFactory::Create();
AbstractThesaurusDialog* pDlg = pFact->CreateThesaurusDialog( pWin, xThes, rWord, nLanguage ); boost::scoped_ptr<AbstractThesaurusDialog> pDlg(pFact->CreateThesaurusDialog( pWin, xThes, rWord, nLanguage ));
WAIT_OFF(); WAIT_OFF();
if ( pDlg->Execute()== RET_OK ) if ( pDlg->Execute()== RET_OK )
{ {
ChangeThesWord( pDlg->GetWord() ); ChangeThesWord( pDlg->GetWord() );
} }
delete pDlg;
} }
@@ -378,13 +378,12 @@ void SvxSpellWrapper::SpellDocument( )
if (xHyphWord.is()) if (xHyphWord.is())
{ {
EditAbstractDialogFactory* pFact = EditAbstractDialogFactory::Create(); EditAbstractDialogFactory* pFact = EditAbstractDialogFactory::Create();
AbstractHyphenWordDialog* pDlg = pFact->CreateHyphenWordDialog( pWin, boost::scoped_ptr<AbstractHyphenWordDialog> pDlg(pFact->CreateHyphenWordDialog( pWin,
xHyphWord->getWord(), xHyphWord->getWord(),
LanguageTag( xHyphWord->getLocale() ).getLanguageType(), LanguageTag( xHyphWord->getLocale() ).getLanguageType(),
xHyph, this ); xHyph, this ));
pWin = pDlg->GetWindow(); pWin = pDlg->GetWindow();
pDlg->Execute(); pDlg->Execute();
delete pDlg;
} }
bDialog = false; bDialog = false;
pWin = pOld; pWin = pOld;

View File

@@ -68,6 +68,7 @@
#include "bib.hrc" #include "bib.hrc"
#include "bibliography.hrc" #include "bibliography.hrc"
#include <connectivity/dbtools.hxx> #include <connectivity/dbtools.hxx>
#include <boost/scoped_ptr.hpp>
using namespace ::com::sun::star; using namespace ::com::sun::star;
using namespace ::com::sun::star::beans; using namespace ::com::sun::star::beans;
@@ -1433,18 +1434,17 @@ void BibDataManager::RemoveMeAsUidListener()
void BibDataManager::CreateMappingDialog(Window* pParent) void BibDataManager::CreateMappingDialog(Window* pParent)
{ {
MappingDialog_Impl* pDlg = new MappingDialog_Impl(pParent, this); boost::scoped_ptr<MappingDialog_Impl> pDlg(new MappingDialog_Impl(pParent, this));
if(RET_OK == pDlg->Execute() && pBibView) if(RET_OK == pDlg->Execute() && pBibView)
{ {
reload(); reload();
} }
delete pDlg;
} }
OUString BibDataManager::CreateDBChangeDialog(Window* pParent) OUString BibDataManager::CreateDBChangeDialog(Window* pParent)
{ {
OUString uRet; OUString uRet;
DBChangeDialog_Impl * pDlg = new DBChangeDialog_Impl(pParent, this ); boost::scoped_ptr<DBChangeDialog_Impl> pDlg(new DBChangeDialog_Impl(pParent, this ));
if(RET_OK == pDlg->Execute()) if(RET_OK == pDlg->Execute())
{ {
OUString sNewURL = pDlg->GetCurrentURL(); OUString sNewURL = pDlg->GetCurrentURL();
@@ -1453,7 +1453,6 @@ OUString BibDataManager::CreateDBChangeDialog(Window* pParent)
uRet = sNewURL; uRet = sNewURL;
} }
} }
delete pDlg;
return uRet; return uRet;
} }

View File

@@ -73,6 +73,7 @@
#include "cursor.hxx" #include "cursor.hxx"
#include "accessibility.hxx" #include "accessibility.hxx"
#include "ElementsDockingWindow.hxx" #include "ElementsDockingWindow.hxx"
#include <boost/scoped_ptr.hpp>
#define MINZOOM 25 #define MINZOOM 25
#define MAXZOOM 800 #define MAXZOOM 800
@@ -562,7 +563,7 @@ void SmGraphicWindow::Command(const CommandEvent& rCEvt)
{ {
GetParent()->ToTop(); GetParent()->ToTop();
SmResId aResId( RID_VIEWMENU ); SmResId aResId( RID_VIEWMENU );
PopupMenu* pPopupMenu = new PopupMenu(aResId); boost::scoped_ptr<PopupMenu> pPopupMenu(new PopupMenu(aResId));
pPopupMenu->SetSelectHdl(LINK(this, SmGraphicWindow, MenuSelectHdl)); pPopupMenu->SetSelectHdl(LINK(this, SmGraphicWindow, MenuSelectHdl));
Point aPos(5, 5); Point aPos(5, 5);
if (rCEvt.IsMouseEvent()) if (rCEvt.IsMouseEvent())
@@ -573,7 +574,6 @@ void SmGraphicWindow::Command(const CommandEvent& rCEvt)
pViewShell->GetViewFrame()->GetBindings().GetDispatcher() pViewShell->GetViewFrame()->GetBindings().GetDispatcher()
->ExecutePopup( aResId, this, &aPos ); ->ExecutePopup( aResId, this, &aPos );
delete pPopupMenu;
bCallBase = false; bCallBase = false;
} }
break; break;
@@ -1749,7 +1749,7 @@ void SmViewShell::Execute(SfxRequest& rReq)
{ {
if ( !GetViewFrame()->GetFrame().IsInPlace() ) if ( !GetViewFrame()->GetFrame().IsInPlace() )
{ {
AbstractSvxZoomDialog *pDlg = 0; boost::scoped_ptr<AbstractSvxZoomDialog> pDlg;
const SfxItemSet *pSet = rReq.GetArgs(); const SfxItemSet *pSet = rReq.GetArgs();
if ( !pSet ) if ( !pSet )
{ {
@@ -1758,7 +1758,7 @@ void SmViewShell::Execute(SfxRequest& rReq)
SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
if(pFact) if(pFact)
{ {
pDlg = pFact->CreateSvxZoomDialog(&GetViewFrame()->GetWindow(), aSet); pDlg.reset(pFact->CreateSvxZoomDialog(&GetViewFrame()->GetWindow(), aSet));
SAL_WARN_IF( !pDlg, "starmath", "Dialog creation failed!" ); SAL_WARN_IF( !pDlg, "starmath", "Dialog creation failed!" );
pDlg->SetLimits( MINZOOM, MAXZOOM ); pDlg->SetLimits( MINZOOM, MAXZOOM );
if( pDlg->Execute() != RET_CANCEL ) if( pDlg->Execute() != RET_CANCEL )
@@ -1797,7 +1797,6 @@ void SmViewShell::Execute(SfxRequest& rReq)
break; break;
} }
} }
delete pDlg;
} }
} }
break; break;