sd/source/ui/view/drviewsf.cxx | 11 +++++------ sd/source/ui/view/outlnvs2.cxx | 39 +++++++++++++++++++-------------------- sd/source/ui/view/outlnvsh.cxx | 4 +--- sd/source/ui/view/sdview.cxx | 11 ++++------- sd/source/ui/view/sdview2.cxx | 7 +++---- sd/source/ui/view/sdview3.cxx | 22 ++++++++++------------ 6 files changed, 42 insertions(+), 52 deletions(-)
New commits: commit f46d9c7d4d5e46a793d9e3dd9211c42007b11c0d Author: Takeshi Abe <t...@fixedpoint.jp> Date: Tue May 27 23:11:57 2014 +0900 Avoid possible memory leaks in case of exceptions Change-Id: Id75c459cfa59fe2adfc0f748dc33d0bc9e271507 diff --git a/sd/source/ui/view/drviewsf.cxx b/sd/source/ui/view/drviewsf.cxx index ea10bdf..6c74365 100644 --- a/sd/source/ui/view/drviewsf.cxx +++ b/sd/source/ui/view/drviewsf.cxx @@ -64,6 +64,7 @@ #include <editeng/adjustitem.hxx> #include <svx/nbdtmgfact.hxx> #include <svx/nbdtmg.hxx> +#include <boost/scoped_ptr.hpp> using namespace svx::sidebar; using namespace ::com::sun::star; @@ -562,7 +563,7 @@ void DrawViewShell::GetAttrState( SfxItemSet& rSet ) aNewAttr.Put( aEditAttr, false ); - SvxNumRule* pNumRule = NULL; + boost::scoped_ptr<SvxNumRule> pNumRule; const SfxPoolItem* pTmpItem=NULL; sal_uInt16 nNumItemId = SID_ATTR_NUMBERING_RULE; @@ -572,7 +573,7 @@ void DrawViewShell::GetAttrState( SfxItemSet& rSet ) pTmpItem=GetNumBulletItem(aNewAttr, nNumItemId); if (pTmpItem) - pNumRule = new SvxNumRule(*((SvxNumBulletItem*)pTmpItem)->GetNumRule()); + pNumRule.reset(new SvxNumRule(*((SvxNumBulletItem*)pTmpItem)->GetNumRule())); if ( pNumRule ) { @@ -626,7 +627,6 @@ void DrawViewShell::GetAttrState( SfxItemSet& rSet ) } } } - delete pNumRule; } } break; @@ -666,11 +666,11 @@ void DrawViewShell::GetAttrState( SfxItemSet& rSet ) nWhich = aIter.NextWhich(); } - SfxItemSet* pSet = NULL; + boost::scoped_ptr<SfxItemSet> pSet; if( bAttr ) { - pSet = new SfxItemSet( GetDoc()->GetPool() ); + pSet.reset(new SfxItemSet( GetDoc()->GetPool() )); mpDrawView->GetAttributes( *pSet ); rSet.Put( *pSet, false ); } @@ -733,7 +733,6 @@ void DrawViewShell::GetAttrState( SfxItemSet& rSet ) rSet.InvalidateItem(EE_CHAR_KERNING); rSet.InvalidateItem(SID_ATTR_CHAR_KERNING); } - delete pSet; } } diff --git a/sd/source/ui/view/outlnvs2.cxx b/sd/source/ui/view/outlnvs2.cxx index 9b88288..0f3812b 100644 --- a/sd/source/ui/view/outlnvs2.cxx +++ b/sd/source/ui/view/outlnvs2.cxx @@ -297,14 +297,14 @@ void OutlineViewShell::FuTemporary(SfxRequest &rReq) case SID_PHOTOALBUM: { SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create(); - VclAbstractDialog* pDlg = pFact ? pFact->CreateSdPhotoAlbumDialog( + boost::scoped_ptr<VclAbstractDialog> pDlg(pFact ? pFact->CreateSdPhotoAlbumDialog( GetActiveWindow(), - GetDoc()) : 0; + GetDoc()) : 0); if (pDlg) { pDlg->Execute(); - delete pDlg; + pDlg.reset(); } Cancel(); rReq.Ignore (); @@ -472,44 +472,44 @@ void OutlineViewShell::FuTemporaryModify(SfxRequest &rReq) case SID_INSERT_FLD_PAGES: case SID_INSERT_FLD_FILE: { - SvxFieldItem* pFieldItem = 0; + boost::scoped_ptr<SvxFieldItem> pFieldItem; switch( nSId ) { case SID_INSERT_FLD_DATE_FIX: - pFieldItem = new SvxFieldItem( - SvxDateField( Date( Date::SYSTEM ), SVXDATETYPE_FIX ), EE_FEATURE_FIELD ); + pFieldItem.reset(new SvxFieldItem( + SvxDateField( Date( Date::SYSTEM ), SVXDATETYPE_FIX ), EE_FEATURE_FIELD )); break; case SID_INSERT_FLD_DATE_VAR: - pFieldItem = new SvxFieldItem( SvxDateField(), EE_FEATURE_FIELD ); + pFieldItem.reset(new SvxFieldItem( SvxDateField(), EE_FEATURE_FIELD )); break; case SID_INSERT_FLD_TIME_FIX: - pFieldItem = new SvxFieldItem( - SvxExtTimeField( Time( Time::SYSTEM ), SVXTIMETYPE_FIX ), EE_FEATURE_FIELD ); + pFieldItem.reset(new SvxFieldItem( + SvxExtTimeField( Time( Time::SYSTEM ), SVXTIMETYPE_FIX ), EE_FEATURE_FIELD )); break; case SID_INSERT_FLD_TIME_VAR: - pFieldItem = new SvxFieldItem( SvxExtTimeField(), EE_FEATURE_FIELD ); + pFieldItem.reset(new SvxFieldItem( SvxExtTimeField(), EE_FEATURE_FIELD )); break; case SID_INSERT_FLD_AUTHOR: { SvtUserOptions aUserOptions; - pFieldItem = new SvxFieldItem( + pFieldItem.reset(new SvxFieldItem( SvxAuthorField( aUserOptions.GetFirstName(), aUserOptions.GetLastName(), aUserOptions.GetID() ) - , EE_FEATURE_FIELD ); + , EE_FEATURE_FIELD )); } break; case SID_INSERT_FLD_PAGE: - pFieldItem = new SvxFieldItem( SvxPageField(), EE_FEATURE_FIELD ); + pFieldItem.reset(new SvxFieldItem( SvxPageField(), EE_FEATURE_FIELD )); break; case SID_INSERT_FLD_PAGES: - pFieldItem = new SvxFieldItem( SvxPagesField(), EE_FEATURE_FIELD ); + pFieldItem.reset(new SvxFieldItem( SvxPagesField(), EE_FEATURE_FIELD )); break; case SID_INSERT_FLD_FILE: @@ -519,7 +519,7 @@ void OutlineViewShell::FuTemporaryModify(SfxRequest &rReq) aName = GetDocSh()->GetMedium()->GetName(); //else // aName = GetDocSh()->GetName(); - pFieldItem = new SvxFieldItem( SvxExtFileField( aName ), EE_FEATURE_FIELD ); + pFieldItem.reset(new SvxFieldItem( SvxExtFileField( aName ), EE_FEATURE_FIELD )); } break; } @@ -545,7 +545,7 @@ void OutlineViewShell::FuTemporaryModify(SfxRequest &rReq) if( pFieldItem ) pOutlinerView->InsertField( *pFieldItem ); - delete pFieldItem; + pFieldItem.reset(); Cancel(); rReq.Ignore (); @@ -563,10 +563,10 @@ void OutlineViewShell::FuTemporaryModify(SfxRequest &rReq) { // Dialog... SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create(); - AbstractSdModifyFieldDlg* pDlg = pFact ? pFact->CreateSdModifyFieldDlg(GetActiveWindow(), pFldItem->GetField(), pOutlinerView->GetAttribs() ) : 0; + boost::scoped_ptr<AbstractSdModifyFieldDlg> pDlg(pFact ? pFact->CreateSdModifyFieldDlg(GetActiveWindow(), pFldItem->GetField(), pOutlinerView->GetAttribs() ) : 0); if( pDlg && (pDlg->Execute() == RET_OK) ) { - SvxFieldData* pField = pDlg->GetField(); + boost::scoped_ptr<SvxFieldData> pField(pDlg->GetField()); if( pField ) { SvxFieldItem aFieldItem( *pField, EE_FEATURE_FIELD ); @@ -588,7 +588,7 @@ void OutlineViewShell::FuTemporaryModify(SfxRequest &rReq) aSel.nEndPos--; pOutlinerView->SetSelection( aSel ); - delete pField; + pField.reset(); } SfxItemSet aSet( pDlg->GetItemSet() ); @@ -601,7 +601,6 @@ void OutlineViewShell::FuTemporaryModify(SfxRequest &rReq) pOutliner->UpdateFields(); } } - delete pDlg; } Cancel(); diff --git a/sd/source/ui/view/outlnvsh.cxx b/sd/source/ui/view/outlnvsh.cxx index fcfb881..291ea39 100644 --- a/sd/source/ui/view/outlnvsh.cxx +++ b/sd/source/ui/view/outlnvsh.cxx @@ -1326,10 +1326,9 @@ void OutlineViewShell::GetStatusBarState(SfxItemSet& rSet) // Zoom-Item if( SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_ATTR_ZOOM ) ) { - SvxZoomItem* pZoomItem; sal_uInt16 nZoom = (sal_uInt16) GetActiveWindow()->GetZoom(); - pZoomItem = new SvxZoomItem( SVX_ZOOM_PERCENT, nZoom ); + boost::scoped_ptr<SvxZoomItem> pZoomItem(new SvxZoomItem( SVX_ZOOM_PERCENT, nZoom )); // limit area sal_uInt16 nZoomValues = SVX_ZOOM_ENABLE_ALL; @@ -1339,7 +1338,6 @@ void OutlineViewShell::GetStatusBarState(SfxItemSet& rSet) pZoomItem->SetValueSet( nZoomValues ); rSet.Put( *pZoomItem ); - delete pZoomItem; } if( SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_ATTR_ZOOMSLIDER ) ) diff --git a/sd/source/ui/view/sdview.cxx b/sd/source/ui/view/sdview.cxx index 53e48a5..59918f3 100644 --- a/sd/source/ui/view/sdview.cxx +++ b/sd/source/ui/view/sdview.cxx @@ -95,6 +95,7 @@ #include "DrawController.hxx" #include <numeric> +#include <boost/scoped_ptr.hpp> using namespace com::sun::star; using namespace com::sun::star::uno; @@ -1247,7 +1248,7 @@ bool View::ShouldToggleOn( return false; bool bToggleOn = false; - SdrOutliner* pOutliner = SdrMakeOutliner(OUTLINERMODE_TEXTOBJECT, pSdrModel); + boost::scoped_ptr<SdrOutliner> pOutliner(SdrMakeOutliner(OUTLINERMODE_TEXTOBJECT, pSdrModel)); sal_uInt32 nMarkCount = GetMarkedObjectCount(); for (sal_uInt32 nIndex = 0; nIndex < nMarkCount && !bToggleOn; nIndex++) { @@ -1297,7 +1298,6 @@ bool View::ShouldToggleOn( pOutliner->Clear(); } } - delete pOutliner; return bToggleOn; } @@ -1320,8 +1320,8 @@ void View::ChangeMarkedObjectsBulletsNumbering( ? false : ShouldToggleOn( bToggle, bHandleBullets ); - SdrOutliner* pOutliner = SdrMakeOutliner(OUTLINERMODE_TEXTOBJECT, pSdrModel); - OutlinerView* pOutlinerView = new OutlinerView(pOutliner, pWindow); + boost::scoped_ptr<SdrOutliner> pOutliner(SdrMakeOutliner(OUTLINERMODE_TEXTOBJECT, pSdrModel)); + boost::scoped_ptr<OutlinerView> pOutlinerView(new OutlinerView(pOutliner.get(), pWindow)); const sal_uInt32 nMarkCount = GetMarkedObjectCount(); for (sal_uInt32 nIndex = 0; nIndex < nMarkCount; nIndex++) @@ -1414,9 +1414,6 @@ void View::ChangeMarkedObjectsBulletsNumbering( } else delete pUndoGroup; - - delete pOutliner; - delete pOutlinerView; } } // end of namespace sd diff --git a/sd/source/ui/view/sdview2.cxx b/sd/source/ui/view/sdview2.cxx index 32e9bde..c1aa044 100644 --- a/sd/source/ui/view/sdview2.cxx +++ b/sd/source/ui/view/sdview2.cxx @@ -65,6 +65,7 @@ #include <vcl/svapp.hxx> #include "slideshow.hxx" +#include <boost/scoped_ptr.hpp> namespace sd { @@ -916,10 +917,10 @@ bool View::GetExchangeList (std::vector<OUString> &rExchangeList, OUString aDesc(SD_RESSTR(STR_DESC_NAMEGROUP)); SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); - AbstractSvxNameDialog* pDlg = 0; + boost::scoped_ptr<AbstractSvxNameDialog> pDlg; if (pFact) - pDlg = pFact->CreateSvxNameDialog( mpViewSh->GetActiveWindow(), aNewName, aDesc ); + pDlg.reset(pFact->CreateSvxNameDialog( mpViewSh->GetActiveWindow(), aNewName, aDesc )); if( pDlg ) { @@ -935,8 +936,6 @@ bool View::GetExchangeList (std::vector<OUString> &rExchangeList, if( !mrDoc.GetObj( aNewName ) ) bNameOK = true; } - - delete pDlg; } } } diff --git a/sd/source/ui/view/sdview3.cxx b/sd/source/ui/view/sdview3.cxx index 89e7aeb..bce24cd 100644 --- a/sd/source/ui/view/sdview3.cxx +++ b/sd/source/ui/view/sdview3.cxx @@ -75,6 +75,7 @@ #include <vcl/cvtgrf.hxx> #include <svx/sdrhittesthelper.hxx> #include <svx/xbtmpit.hxx> +#include <boost/scoped_ptr.hpp> // - Namespaces - @@ -265,7 +266,7 @@ bool View::InsertData( const TransferableDataHelper& rDataHelper, TransferableDataHelper aDataHelper( rDataHelper ); SdrObject* pPickObj = NULL; SdPage* pPage = NULL; - ImageMap* pImageMap = NULL; + boost::scoped_ptr<ImageMap> pImageMap; bool bReturn = false; bool bLink = ( ( mnAction & DND_ACTION_LINK ) != 0 ); bool bCopy = ( ( ( mnAction & DND_ACTION_COPY ) != 0 ) || bLink ); @@ -316,7 +317,7 @@ bool View::InsertData( const TransferableDataHelper& rDataHelper, if( aDataHelper.GetSotStorageStream( SOT_FORMATSTR_ID_SVIM, xStm ) ) { - pImageMap = new ImageMap; + pImageMap.reset(new ImageMap); // mba: clipboard always must contain absolute URLs (could be from alien source) pImageMap->Read( *xStm, OUString() ); } @@ -1165,7 +1166,7 @@ bool View::InsertData( const TransferableDataHelper& rDataHelper, if( !bReturn && aDataHelper.HasFormat( FORMAT_GDIMETAFILE ) ) { // if no object was inserted, insert a picture - InsertMetaFile( aDataHelper, rPos, pImageMap, true ); + InsertMetaFile( aDataHelper, rPos, pImageMap.get(), true ); bReturn = true; } } @@ -1203,7 +1204,7 @@ bool View::InsertData( const TransferableDataHelper& rDataHelper, ImpCheckInsertPos(aInsertPos, aImageMapSize, GetWorkArea()); - InsertGraphic( aGraphic, mnAction, aInsertPos, NULL, pImageMap ); + InsertGraphic( aGraphic, mnAction, aInsertPos, NULL, pImageMap.get() ); bReturn = true; } } @@ -1229,7 +1230,7 @@ bool View::InsertData( const TransferableDataHelper& rDataHelper, aInsertPos.Y() = pOwnData->GetStartPos().Y() + ( aSize.Height() >> 1 ); } - bReturn = InsertMetaFile( aDataHelper, aInsertPos, pImageMap, nFormat == 0 ); + bReturn = InsertMetaFile( aDataHelper, aInsertPos, pImageMap.get(), nFormat == 0 ); } if(!bReturn && (!bLink || pPickObj) && CHECK_FORMAT_TRANS(FORMAT_BITMAP)) @@ -1282,7 +1283,7 @@ bool View::InsertData( const TransferableDataHelper& rDataHelper, Size aImageMapSize(aBmpEx.GetPrefSize()); ImpCheckInsertPos(aInsertPos, aImageMapSize, GetWorkArea()); - InsertGraphic( aBmpEx, mnAction, aInsertPos, NULL, pImageMap ); + InsertGraphic( aBmpEx, mnAction, aInsertPos, NULL, pImageMap.get() ); bReturn = true; } } @@ -1488,29 +1489,26 @@ bool View::InsertData( const TransferableDataHelper& rDataHelper, MarkListHasChanged(); mbIsDropAllowed = true; rDnDAction = mnAction; - delete pImageMap; return bReturn; } bool View::PasteRTFTable( SotStorageStreamRef xStm, SdrPage* pPage, sal_uLong nPasteOptions ) { - SdDrawDocument* pModel = new SdDrawDocument( DOCUMENT_TYPE_IMPRESS, mpDocSh ); + boost::scoped_ptr<SdDrawDocument> pModel(new SdDrawDocument( DOCUMENT_TYPE_IMPRESS, mpDocSh )); pModel->NewOrLoadCompleted(NEW_DOC); pModel->GetItemPool().SetDefaultMetric(SFX_MAPUNIT_100TH_MM); pModel->InsertPage(pModel->AllocPage(false)); - Reference< XComponent > xComponent( new SdXImpressDocument( pModel, true ) ); + Reference< XComponent > xComponent( new SdXImpressDocument( pModel.get(), true ) ); pModel->setUnoModel( Reference< XInterface >::query( xComponent ) ); - CreateTableFromRTF( *xStm, pModel ); + CreateTableFromRTF( *xStm, pModel.get() ); bool bRet = Paste( *pModel, maDropPos, pPage, nPasteOptions ); xComponent->dispose(); xComponent.clear(); - delete pModel; - return bRet; } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits