From 2c61edfdf57dabbd86ecc440444b6b00443f916a Mon Sep 17 00:00:00 2001 From: Takeshi Abe Date: Thu, 22 May 2014 00:36:41 +0900 Subject: Avoid possible memory leaks in case of exceptions Change-Id: Ic88b22895c2eb4144d31f22a0f7bc98971873262 --- sd/source/ui/func/fuparagr.cxx | 7 ++----- sd/source/ui/func/fuprlout.cxx | 4 ++-- sd/source/ui/func/fuprobjs.cxx | 5 +++-- sd/source/ui/func/fuscale.cxx | 17 +++++++---------- sd/source/ui/func/fusldlg.cxx | 4 ++-- sd/source/ui/func/fusnapln.cxx | 5 +++-- sd/source/ui/func/futempl.cxx | 13 +++++-------- sd/source/ui/func/futxtatt.cxx | 7 ++----- sd/source/ui/func/fuvect.cxx | 4 ++-- 9 files changed, 28 insertions(+), 38 deletions(-) (limited to 'sd') diff --git a/sd/source/ui/func/fuparagr.cxx b/sd/source/ui/func/fuparagr.cxx index de0dc0e35933..08db2fb6dc3d 100644 --- a/sd/source/ui/func/fuparagr.cxx +++ b/sd/source/ui/func/fuparagr.cxx @@ -34,6 +34,7 @@ #include "drawdoc.hxx" #include "sdabstdlg.hxx" #include "sdattr.hrc" +#include namespace sd { @@ -90,7 +91,7 @@ void FuParagraph::DoExecute( SfxRequest& rReq ) } SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create(); - SfxAbstractTabDialog* pDlg = pFact ? pFact->CreateSdParagraphTabDlg(NULL, &aNewAttr ) : 0; + boost::scoped_ptr pDlg(pFact ? pFact->CreateSdParagraphTabDlg(NULL, &aNewAttr ) : 0); if (!pDlg) return; @@ -107,12 +108,8 @@ void FuParagraph::DoExecute( SfxRequest& rReq ) break; default: - { - delete pDlg; - } return; // Cancel } - delete( pDlg ); } mpView->SetAttributes( *pArgs ); diff --git a/sd/source/ui/func/fuprlout.cxx b/sd/source/ui/func/fuprlout.cxx index 10f58307354e..702a10f79718 100644 --- a/sd/source/ui/func/fuprlout.cxx +++ b/sd/source/ui/func/fuprlout.cxx @@ -51,6 +51,7 @@ #include #include #include "sdabstdlg.hxx" +#include namespace sd { @@ -148,7 +149,7 @@ void FuPresentationLayout::DoExecute( SfxRequest& rReq ) else { SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create(); - AbstractSdPresLayoutDlg* pDlg = pFact ? pFact->CreateSdPresLayoutDlg(mpDocSh, NULL, aSet ) : 0; + boost::scoped_ptr pDlg(pFact ? pFact->CreateSdPresLayoutDlg(mpDocSh, NULL, aSet ) : 0); sal_uInt16 nResult = pDlg ? pDlg->Execute() : static_cast(RET_CANCEL); @@ -171,7 +172,6 @@ void FuPresentationLayout::DoExecute( SfxRequest& rReq ) default: bError = true; } - delete pDlg; } if (!bError) diff --git a/sd/source/ui/func/fuprobjs.cxx b/sd/source/ui/func/fuprobjs.cxx index a200955bb51f..57536ef76721 100644 --- a/sd/source/ui/func/fuprobjs.cxx +++ b/sd/source/ui/func/fuprobjs.cxx @@ -41,6 +41,8 @@ #include "prlayout.hxx" #include "unchss.hxx" #include "sdabstdlg.hxx" +#include + namespace sd { TYPEINIT1( FuPresentationObjects, FuPoor ); @@ -142,7 +144,7 @@ void FuPresentationObjects::DoExecute( SfxRequest& ) SfxStyleSheetBase& rStyleSheet = *pStyleSheet; SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create(); - SfxAbstractTabDialog* pDlg = pFact ? pFact->CreateSdPresLayoutTemplateDlg( mpDocSh, NULL, SdResId( nDlgId ), rStyleSheet, ePO, pStyleSheetPool ) : 0; + boost::scoped_ptr pDlg(pFact ? pFact->CreateSdPresLayoutTemplateDlg( mpDocSh, NULL, SdResId( nDlgId ), rStyleSheet, ePO, pStyleSheetPool ) : 0); if( pDlg && (pDlg->Execute() == RET_OK) ) { const SfxItemSet* pOutSet = pDlg->GetOutputItemSet(); @@ -155,7 +157,6 @@ void FuPresentationObjects::DoExecute( SfxRequest& ) pStyleSheet->GetItemSet().Put( *pOutSet ); ( (SfxStyleSheet*) pStyleSheet )->Broadcast( SfxSimpleHint( SFX_HINT_DATACHANGED ) ); } - delete( pDlg ); } } } diff --git a/sd/source/ui/func/fuscale.cxx b/sd/source/ui/func/fuscale.cxx index 957eb0025b00..04c8718bc40d 100644 --- a/sd/source/ui/func/fuscale.cxx +++ b/sd/source/ui/func/fuscale.cxx @@ -39,6 +39,7 @@ #include #include #include +#include namespace sd { @@ -70,7 +71,7 @@ void FuScale::DoExecute( SfxRequest& rReq ) if( !pArgs ) { SfxItemSet aNewAttr( mpDoc->GetPool(), SID_ATTR_ZOOM, SID_ATTR_ZOOM ); - SvxZoomItem* pZoomItem; + boost::scoped_ptr pZoomItem; sal_uInt16 nZoomValues = SVX_ZOOM_ENABLE_ALL; nValue = (sal_Int16) mpWindow->GetZoom(); @@ -79,11 +80,11 @@ void FuScale::DoExecute( SfxRequest& rReq ) if( mpViewShell && mpViewShell->ISA( DrawViewShell ) && static_cast(mpViewShell)->IsZoomOnPage() ) { - pZoomItem = new SvxZoomItem( SVX_ZOOM_WHOLEPAGE, nValue ); + pZoomItem.reset(new SvxZoomItem( SVX_ZOOM_WHOLEPAGE, nValue )); } else { - pZoomItem = new SvxZoomItem( SVX_ZOOM_PERCENT, nValue ); + pZoomItem.reset(new SvxZoomItem( SVX_ZOOM_PERCENT, nValue )); } // limit range @@ -109,11 +110,11 @@ void FuScale::DoExecute( SfxRequest& rReq ) pZoomItem->SetValueSet( nZoomValues ); aNewAttr.Put( *pZoomItem ); - AbstractSvxZoomDialog* pDlg=NULL; + boost::scoped_ptr pDlg; SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); if(pFact) { - pDlg = pFact->CreateSvxZoomDialog(NULL, aNewAttr); + pDlg.reset(pFact->CreateSvxZoomDialog(NULL, aNewAttr)); } if( pDlg ) @@ -124,8 +125,6 @@ void FuScale::DoExecute( SfxRequest& rReq ) { case RET_CANCEL: { - delete pDlg; - delete pZoomItem; rReq.Ignore (); return; // Cancel } @@ -141,7 +140,7 @@ void FuScale::DoExecute( SfxRequest& rReq ) const SfxItemSet aArgs (*(pDlg->GetOutputItemSet ())); - delete pDlg; + pDlg.reset(); switch (((const SvxZoomItem &) aArgs.Get (SID_ATTR_ZOOM)).GetType ()) { @@ -177,8 +176,6 @@ void FuScale::DoExecute( SfxRequest& rReq ) break; } } - - delete pZoomItem; } else if(mpViewShell && (pArgs->Count () == 1)) { diff --git a/sd/source/ui/func/fusldlg.cxx b/sd/source/ui/func/fusldlg.cxx index ea5333cf133d..6f60d3cc98d7 100644 --- a/sd/source/ui/func/fusldlg.cxx +++ b/sd/source/ui/func/fusldlg.cxx @@ -32,6 +32,7 @@ #include "Window.hxx" #include "optsitem.hxx" #include "sdabstdlg.hxx" +#include namespace sd { @@ -110,7 +111,7 @@ void FuSlideShowDlg::DoExecute( SfxRequest& ) aDlgSet.Put( SfxInt32Item( ATTR_PRESENT_DISPLAY, pOptions->GetDisplay() ) ); SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create(); - AbstractSdStartPresDlg* pDlg = pFact ? pFact->CreateSdStartPresentationDlg(mpWindow, aDlgSet, aPageNameList, pCustomShowList) : 0; + boost::scoped_ptr pDlg(pFact ? pFact->CreateSdStartPresentationDlg(mpWindow, aDlgSet, aPageNameList, pCustomShowList) : 0); if( pDlg && (pDlg->Execute() == RET_OK) ) { OUString aPage; @@ -224,7 +225,6 @@ void FuSlideShowDlg::DoExecute( SfxRequest& ) if ( bValuesChanged ) mpDoc->SetChanged( true ); } - delete pDlg; } } // end of namespace sd diff --git a/sd/source/ui/func/fusnapln.cxx b/sd/source/ui/func/fusnapln.cxx index 69e50f0f28d6..79f438a54379 100644 --- a/sd/source/ui/func/fusnapln.cxx +++ b/sd/source/ui/func/fusnapln.cxx @@ -36,6 +36,7 @@ #include "sdabstdlg.hxx" #include "app.hrc" #include +#include namespace sd { @@ -112,7 +113,7 @@ void FuSnapLine::DoExecute( SfxRequest& rReq ) aNewAttr.Put(SfxUInt32Item(ATTR_SNAPLINE_Y, aLinePos.Y())); SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create(); - AbstractSdSnapLineDlg* pDlg = pFact ? pFact->CreateSdSnapLineDlg( NULL, aNewAttr, mpView ) : 0; + boost::scoped_ptr pDlg(pFact ? pFact->CreateSdSnapLineDlg( NULL, aNewAttr, mpView ) : 0); OSL_ASSERT(pDlg); if (!pDlg) return; @@ -145,7 +146,7 @@ void FuSnapLine::DoExecute( SfxRequest& rReq ) sal_uInt16 nResult = pDlg->Execute(); pDlg->GetAttr(aNewAttr); - delete pDlg; + pDlg.reset(); switch( nResult ) { diff --git a/sd/source/ui/func/futempl.cxx b/sd/source/ui/func/futempl.cxx index 1dd0c403ba20..c6d1b6d2c12a 100644 --- a/sd/source/ui/func/futempl.cxx +++ b/sd/source/ui/func/futempl.cxx @@ -65,6 +65,7 @@ #include "strings.hrc" #include "helpids.h" #include "sdabstdlg.hxx" +#include using namespace com::sun::star::uno; using namespace com::sun::star::container; @@ -296,8 +297,8 @@ void FuTemplate::DoExecute( SfxRequest& rReq ) if( pStyleSheet ) { - SfxAbstractTabDialog* pStdDlg = NULL; - SfxAbstractTabDialog* pPresDlg = NULL; + boost::scoped_ptr pStdDlg; + boost::scoped_ptr pPresDlg; SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create(); bool bOldDocInOtherLanguage = false; SfxItemSet aOriSet( pStyleSheet->GetItemSet() ); @@ -306,7 +307,7 @@ void FuTemplate::DoExecute( SfxRequest& rReq ) if (eFamily == SD_STYLE_FAMILY_GRAPHICS) { - pStdDlg = pFact ? pFact->CreateSdTabTemplateDlg( 0, mpDoc->GetDocSh(), *pStyleSheet, mpDoc, mpView ) : 0; + pStdDlg.reset(pFact ? pFact->CreateSdTabTemplateDlg( 0, mpDoc->GetDocSh(), *pStyleSheet, mpDoc, mpView ) : 0); } else if (eFamily == SD_STYLE_FAMILY_PSEUDO) { @@ -370,7 +371,7 @@ void FuTemplate::DoExecute( SfxRequest& rReq ) if( !bOldDocInOtherLanguage ) { - pPresDlg = pFact ? pFact->CreateSdPresLayoutTemplateDlg( mpDocSh, NULL, SdResId(nDlgId), *pStyleSheet, ePO, pSSPool ) : 0; + pPresDlg.reset(pFact ? pFact->CreateSdPresLayoutTemplateDlg( mpDocSh, NULL, SdResId(nDlgId), *pStyleSheet, ePO, pSSPool ) : 0); } } else if (eFamily == SD_STYLE_FAMILY_CELL) @@ -579,13 +580,9 @@ void FuTemplate::DoExecute( SfxRequest& rReq ) { if( nSId == SID_STYLE_NEW ) pSSPool->Remove( pStyleSheet ); - delete pStdDlg; - delete pPresDlg; } return; // Cancel } - delete pStdDlg; - delete pPresDlg; } } break; diff --git a/sd/source/ui/func/futxtatt.cxx b/sd/source/ui/func/futxtatt.cxx index bdfbfcb443ad..5db7226dfbb2 100644 --- a/sd/source/ui/func/futxtatt.cxx +++ b/sd/source/ui/func/futxtatt.cxx @@ -26,6 +26,7 @@ #include "View.hxx" #include "ViewShell.hxx" #include "drawdoc.hxx" +#include namespace sd { @@ -58,7 +59,7 @@ void FuTextAttrDlg::DoExecute( SfxRequest& rReq ) if( !pArgs ) { SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); - SfxAbstractTabDialog *pDlg = pFact->CreateTextTabDialog( NULL, &aNewAttr, mpView ); + boost::scoped_ptr pDlg(pFact->CreateTextTabDialog( NULL, &aNewAttr, mpView )); sal_uInt16 nResult = pDlg->Execute(); @@ -73,12 +74,8 @@ void FuTextAttrDlg::DoExecute( SfxRequest& rReq ) break; default: - { - delete( pDlg ); - } return; // Cancel } - delete( pDlg ); } mpView->SetAttributes( *pArgs ); } diff --git a/sd/source/ui/func/fuvect.cxx b/sd/source/ui/func/fuvect.cxx index 2efec4b1266b..97e3f1101b7c 100644 --- a/sd/source/ui/func/fuvect.cxx +++ b/sd/source/ui/func/fuvect.cxx @@ -30,6 +30,7 @@ #include "strings.hrc" #include "sdresid.hxx" #include "sdabstdlg.hxx" +#include namespace sd { @@ -64,7 +65,7 @@ void FuVectorize::DoExecute( SfxRequest& ) if( pObj && pObj->ISA( SdrGrafObj ) ) { SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create(); - AbstractSdVectorizeDlg* pDlg = pFact ? pFact->CreateSdVectorizeDlg( mpWindow, ( (SdrGrafObj*) pObj )->GetGraphic().GetBitmap(), mpDocSh ) : 0; + boost::scoped_ptr pDlg(pFact ? pFact->CreateSdVectorizeDlg( mpWindow, ( (SdrGrafObj*) pObj )->GetGraphic().GetBitmap(), mpDocSh ) : 0); if( pDlg && pDlg->Execute() == RET_OK ) { const GDIMetaFile& rMtf = pDlg->GetGDIMetaFile(); @@ -81,7 +82,6 @@ void FuVectorize::DoExecute( SfxRequest& ) mpView->EndUndo(); } } - delete pDlg; } } } -- cgit v1.2.3