sc/source/ui/view/printfun.cxx | 15 +++++---------- sc/source/ui/view/tabvwsh3.cxx | 14 ++++---------- sc/source/ui/view/tabvwshf.cxx | 19 +++++++------------ sc/source/ui/view/viewfun2.cxx | 22 ++++++++-------------- sc/source/ui/view/viewfun3.cxx | 19 +++++++++---------- 5 files changed, 33 insertions(+), 56 deletions(-)
New commits: commit 34ae7b16d7ef365f4b63dd3d4a9e756e2b77e7bd Author: Takeshi Abe <t...@fixedpoint.jp> Date: Thu May 8 00:09:02 2014 +0900 Avoid possible memory leaks in case of exceptions Change-Id: Idf1460e5207e0797390593535f2b2c080609a77b diff --git a/sc/source/ui/view/printfun.cxx b/sc/source/ui/view/printfun.cxx index 2f76e43..f3cb9b6 100644 --- a/sc/source/ui/view/printfun.cxx +++ b/sc/source/ui/view/printfun.cxx @@ -523,14 +523,14 @@ void ScPrintFunc::DrawToDev( ScDocument* pDoc, OutputDevice* pDev, double /* nPr // #114135# ScDrawLayer* pModel = pDoc->GetDrawLayer(); - FmFormView* pDrawView = NULL; + boost::scoped_ptr<FmFormView> pDrawView; if( pModel ) { - pDrawView = new FmFormView( pModel, pDev ); + pDrawView.reset(new FmFormView( pModel, pDev )); pDrawView->ShowSdrPage(pDrawView->GetModel()->GetPage(nTab)); pDrawView->SetPrintPreview( true ); - aOutputData.SetDrawView( pDrawView ); + aOutputData.SetDrawView( pDrawView.get() ); } //! SetUseStyleColor ?? @@ -594,9 +594,6 @@ void ScPrintFunc::DrawToDev( ScDocument* pDoc, OutputDevice* pDev, double /* nPr aOutputData.PrintDrawingLayer(SC_LAYER_FRONT, aMMOffset); aOutputData.PrintDrawingLayer(SC_LAYER_INTERN, aMMOffset); aOutputData.PostPrintDrawingLayer(aMMOffset); // #i74768# - - // #114135# - delete pDrawView; } @@ -1346,7 +1343,7 @@ void ScPrintFunc::DrawBorder( long nScrX, long nScrY, long nScrW, long nScrH, if (pBorderData) { - ScDocument* pBorderDoc = new ScDocument( SCDOCMODE_UNDO ); + boost::scoped_ptr<ScDocument> pBorderDoc(new ScDocument( SCDOCMODE_UNDO )); pBorderDoc->InitUndo( pDoc, 0,0, true,true ); if (pBorderData) pBorderDoc->ApplyAttr( 0,0,0, *pBorderData ); @@ -1360,14 +1357,12 @@ void ScPrintFunc::DrawBorder( long nScrX, long nScrY, long nScrW, long nScrH, aTabInfo.mpRowInfo[0].pCellInfo[1].nWidth = aTabInfo.mpRowInfo[1].pCellInfo[1].nWidth = (sal_uInt16) nEffWidth; - ScOutputData aOutputData( pDev, OUTTYPE_PRINTER, aTabInfo, pBorderDoc, 0, + ScOutputData aOutputData( pDev, OUTTYPE_PRINTER, aTabInfo, pBorderDoc.get(), 0, nScrX+nLeft, nScrY+nTop, 0,0, 0,0, nScaleX, nScaleY ); aOutputData.SetUseStyleColor( bUseStyleColor ); if (pBorderData) aOutputData.DrawFrame(); - - delete pBorderDoc; } } diff --git a/sc/source/ui/view/tabvwsh3.cxx b/sc/source/ui/view/tabvwsh3.cxx index 2b66df4..7c2a2c2 100644 --- a/sc/source/ui/view/tabvwsh3.cxx +++ b/sc/source/ui/view/tabvwsh3.cxx @@ -647,7 +647,7 @@ void ScTabViewShell::Execute( SfxRequest& rReq ) { SfxItemSet aSet ( GetPool(), SID_ATTR_ZOOM, SID_ATTR_ZOOM ); SvxZoomItem aZoomItem( eOldZoomType, nOldZoom, SID_ATTR_ZOOM ); - AbstractSvxZoomDialog* pDlg = NULL; + boost::scoped_ptr<AbstractSvxZoomDialog> pDlg; ScMarkData& rMark = GetViewData()->GetMarkData(); sal_uInt16 nBtnFlags = SVX_ZOOM_ENABLE_50 | SVX_ZOOM_ENABLE_75 @@ -665,7 +665,7 @@ void ScTabViewShell::Execute( SfxRequest& rReq ) SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); if(pFact) { - pDlg = pFact->CreateSvxZoomDialog(GetDialogParent(), aSet ); + pDlg.reset(pFact->CreateSvxZoomDialog(GetDialogParent(), aSet )); OSL_ENSURE(pDlg, "Dialogdiet fail!"); } if (pDlg) @@ -685,8 +685,6 @@ void ScTabViewShell::Execute( SfxRequest& rReq ) eNewZoomType = rZoomItem.GetType(); nZoom = rZoomItem.GetValue(); } - - delete pDlg; } } @@ -966,7 +964,6 @@ void ScTabViewShell::Execute( SfxRequest& rReq ) case FID_PROTECT_DOC: { ScDocument* pDoc = GetViewData()->GetDocument(); - SfxPasswordDialog* pDlg; if( pReqArgs ) { @@ -989,7 +986,7 @@ void ScTabViewShell::Execute( SfxRequest& rReq ) { OUString aText(ScResId(SCSTR_PASSWORD)); - pDlg = new SfxPasswordDialog(GetDialogParent(), &aText); + boost::scoped_ptr<SfxPasswordDialog> pDlg(new SfxPasswordDialog(GetDialogParent(), &aText)); pDlg->SetText( ScResId(SCSTR_UNPROTECTDOC) ); pDlg->SetMinLen( 0 ); pDlg->SetHelpId( GetStaticInterface()->GetSlot(FID_PROTECT_DOC)->GetCommand() ); @@ -999,7 +996,6 @@ void ScTabViewShell::Execute( SfxRequest& rReq ) aPassword = pDlg->GetPassword(); else bCancel = true; - delete pDlg; } if (!bCancel) { @@ -1012,7 +1008,7 @@ void ScTabViewShell::Execute( SfxRequest& rReq ) { OUString aText(ScResId(SCSTR_PASSWORDOPT)); - pDlg = new SfxPasswordDialog( GetDialogParent(), &aText ); + boost::scoped_ptr<SfxPasswordDialog> pDlg(new SfxPasswordDialog(GetDialogParent(), &aText)); pDlg->SetText( ScResId(SCSTR_PROTECTDOC) ); pDlg->SetMinLen( 0 ); pDlg->SetHelpId( GetStaticInterface()->GetSlot(FID_PROTECT_DOC)->GetCommand() ); @@ -1026,8 +1022,6 @@ void ScTabViewShell::Execute( SfxRequest& rReq ) rReq.AppendItem( SfxBoolItem( FID_PROTECT_DOC, true ) ); rReq.Done(); } - - delete pDlg; } rBindings.Invalidate( FID_PROTECT_DOC ); } diff --git a/sc/source/ui/view/tabvwshf.cxx b/sc/source/ui/view/tabvwshf.cxx index bf9de04..8055546 100644 --- a/sc/source/ui/view/tabvwshf.cxx +++ b/sc/source/ui/view/tabvwshf.cxx @@ -131,7 +131,7 @@ void ScTabViewShell::ExecuteTable( SfxRequest& rReq ) ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); OSL_ENSURE(pFact, "ScAbstractFactory create fail!"); - AbstractScShowTabDlg* pDlg = pFact->CreateScShowTabDlg(GetDialogParent()); + boost::scoped_ptr<AbstractScShowTabDlg> pDlg(pFact->CreateScShowTabDlg(GetDialogParent())); OSL_ENSURE(pDlg, "Dialog create fail!"); OUString aTabName; @@ -158,7 +158,6 @@ void ScTabViewShell::ExecuteTable( SfxRequest& rReq ) ShowTable( rNames ); rReq.Done(); } - delete pDlg; } } break; @@ -200,8 +199,8 @@ void ScTabViewShell::ExecuteTable( SfxRequest& rReq ) ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); OSL_ENSURE(pFact, "ScAbstractFactory create fail!"); - AbstractScInsertTableDlg* pDlg = pFact->CreateScInsertTableDlg(GetDialogParent(), *pViewData, - nTabSelCount, nSlot == FID_INS_TABLE_EXT); + boost::scoped_ptr<AbstractScInsertTableDlg> pDlg(pFact->CreateScInsertTableDlg(GetDialogParent(), *pViewData, + nTabSelCount, nSlot == FID_INS_TABLE_EXT)); OSL_ENSURE(pDlg, "Dialog create fail!"); if ( RET_OK == pDlg->Execute() ) { @@ -292,8 +291,6 @@ void ScTabViewShell::ExecuteTable( SfxRequest& rReq ) } } } - - delete pDlg; } } break; @@ -374,10 +371,10 @@ void ScTabViewShell::ExecuteTable( SfxRequest& rReq ) ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); OSL_ENSURE(pFact, "ScAbstractFactory create fail!"); - AbstractScStringInputDlg* pDlg = pFact->CreateScStringInputDlg( + boost::scoped_ptr<AbstractScStringInputDlg> pDlg(pFact->CreateScStringInputDlg( GetDialogParent(), aDlgTitle, OUString(ScResId(SCSTR_NAME)), aName, GetStaticInterface()->GetSlot(nSlot)->GetCommand(), - pHelpId); + pHelpId)); OSL_ENSURE(pDlg, "Dialog create fail!"); @@ -423,7 +420,6 @@ void ScTabViewShell::ExecuteTable( SfxRequest& rReq ) } } } - delete pDlg; } } break; @@ -502,8 +498,8 @@ void ScTabViewShell::ExecuteTable( SfxRequest& rReq ) ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); OSL_ENSURE(pFact, "ScAbstractFactory create fail!"); - AbstractScMoveTableDlg* pDlg = pFact->CreateScMoveTableDlg(GetDialogParent(), - aDefaultName); + boost::scoped_ptr<AbstractScMoveTableDlg> pDlg(pFact->CreateScMoveTableDlg(GetDialogParent(), + aDefaultName)); OSL_ENSURE(pDlg, "Dialog create fail!"); SCTAB nTableCount = pDoc->GetTableCount(); @@ -553,7 +549,6 @@ void ScTabViewShell::ExecuteTable( SfxRequest& rReq ) rReq.AppendItem( SfxUInt16Item( FN_PARAM_1, static_cast<sal_uInt16>(nBasicTab) ) ); rReq.AppendItem( SfxBoolItem( FN_PARAM_2, bCpy ) ); } - delete pDlg; } if( bDoIt ) diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx index 6bfb61c..3bbb8e2 100644 --- a/sc/source/ui/view/viewfun2.cxx +++ b/sc/source/ui/view/viewfun2.cxx @@ -779,7 +779,7 @@ void ScViewFunc::EnterBlock( const OUString& rString, const EditTextObject* pDat ScAddress aPos( nCol, nRow, nTab ); - ScDocument* pInsDoc = new ScDocument( SCDOCMODE_CLIP ); + boost::scoped_ptr<ScDocument> pInsDoc(new ScDocument( SCDOCMODE_CLIP )); pInsDoc->ResetClip( pDoc, nTab ); if (aNewStr[0] == '=') // Formula ? @@ -797,7 +797,7 @@ void ScViewFunc::EnterBlock( const OUString& rString, const EditTextObject* pDat pInsDoc->SetClipArea( ScRange(aPos) ); // insert Block, with Undo etc. - if ( PasteFromClip( IDF_CONTENTS, pInsDoc, PASTE_NOFUNC, false, false, + if ( PasteFromClip( IDF_CONTENTS, pInsDoc.get(), PASTE_NOFUNC, false, false, false, INS_NONE, IDF_ATTRIB ) ) { const SfxUInt32Item* pItem = (SfxUInt32Item*) pInsDoc->GetAttr( @@ -807,16 +807,13 @@ void ScViewFunc::EnterBlock( const OUString& rString, const EditTextObject* pDat // MarkData was already MarkToSimple'ed in PasteFromClip ScRange aRange; rMark.GetMarkArea( aRange ); - ScPatternAttr* pPattern = new ScPatternAttr( pDoc->GetPool() ); + boost::scoped_ptr<ScPatternAttr> pPattern(new ScPatternAttr( pDoc->GetPool() )); pPattern->GetItemSet().Put( *pItem ); short nNewType = pDoc->GetFormatTable()->GetType( pItem->GetValue() ); pDoc->ApplyPatternIfNumberformatIncompatible( aRange, rMark, *pPattern, nNewType ); - delete pPattern; } } - - delete pInsDoc; } // manual page break @@ -2883,14 +2880,14 @@ void ScViewFunc::SetSelectionFrameLines( const SvxBorderLine* pLine, // none of the lines don't care? if( (eItemState != SFX_ITEM_DONTCARE) && (eTLBRState != SFX_ITEM_DONTCARE) && (eBLTRState != SFX_ITEM_DONTCARE) ) { - SfxItemSet* pOldSet = new SfxItemSet( + boost::scoped_ptr<SfxItemSet> pOldSet(new SfxItemSet( *(pDoc->GetPool()), ATTR_PATTERN_START, - ATTR_PATTERN_END ); - SfxItemSet* pNewSet = new SfxItemSet( + ATTR_PATTERN_END )); + boost::scoped_ptr<SfxItemSet> pNewSet(new SfxItemSet( *(pDoc->GetPool()), ATTR_PATTERN_START, - ATTR_PATTERN_END ); + ATTR_PATTERN_END )); const SvxBorderLine* pBoxLine = NULL; @@ -2935,10 +2932,7 @@ void ScViewFunc::SetSelectionFrameLines( const SvxBorderLine* pLine, pNewSet->Put( aBLTRItem ); } - ApplyAttributes( pNewSet, pOldSet ); - - delete pOldSet; - delete pNewSet; + ApplyAttributes( pNewSet.get(), pOldSet.get() ); } else // if ( eItemState == SFX_ITEM_DONTCARE ) { diff --git a/sc/source/ui/view/viewfun3.cxx b/sc/source/ui/view/viewfun3.cxx index b548313..2f7375e 100644 --- a/sc/source/ui/view/viewfun3.cxx +++ b/sc/source/ui/view/viewfun3.cxx @@ -65,6 +65,7 @@ #include "undodat.hxx" #include "drawview.hxx" #include "cliputil.hxx" +#include <boost/scoped_ptr.hpp> using namespace com::sun::star; @@ -1206,16 +1207,16 @@ bool ScViewFunc::PasteFromClip( sal_uInt16 nFlags, ScDocument* pClipDoc, // wenn gerechnet werden soll, Originaldaten merken - ScDocument* pMixDoc = NULL; + boost::scoped_ptr<ScDocument> pMixDoc; if (nFunction) { bSkipEmpty = false; if ( nFlags & IDF_CONTENTS ) { - pMixDoc = new ScDocument( SCDOCMODE_UNDO ); + pMixDoc.reset(new ScDocument( SCDOCMODE_UNDO )); pMixDoc->InitUndo( pDoc, nStartTab, nEndTab ); pDoc->CopyToDocument( nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab, - IDF_CONTENTS, false, pMixDoc ); + IDF_CONTENTS, false, pMixDoc.get() ); } } @@ -1261,9 +1262,9 @@ bool ScViewFunc::PasteFromClip( sal_uInt16 nFlags, ScDocument* pClipDoc, if ( pMixDoc ) // Rechenfunktionen mit Original-Daten auszufuehren ? { - pDoc->MixDocument( aUserRange, nFunction, bSkipEmpty, pMixDoc ); + pDoc->MixDocument( aUserRange, nFunction, bSkipEmpty, pMixDoc.get() ); } - delete pMixDoc; + pMixDoc.reset(); AdjustBlockHeight(); // update row heights before pasting objects @@ -1854,10 +1855,10 @@ bool ScViewFunc::LinkBlock( const ScRange& rSource, const ScAddress& rDestPos, b // Ausfuehren per Paste ScDocument* pDoc = GetViewData()->GetDocument(); - ScDocument* pClipDoc = new ScDocument( SCDOCMODE_CLIP ); + boost::scoped_ptr<ScDocument> pClipDoc(new ScDocument( SCDOCMODE_CLIP )); pDoc->CopyTabToClip( rSource.aStart.Col(), rSource.aStart.Row(), rSource.aEnd.Col(), rSource.aEnd.Row(), - rSource.aStart.Tab(), pClipDoc ); + rSource.aStart.Tab(), pClipDoc.get() ); // Zielbereich markieren (Cursor setzen, keine Markierung) @@ -1868,9 +1869,7 @@ bool ScViewFunc::LinkBlock( const ScRange& rSource, const ScAddress& rDestPos, b // Paste - PasteFromClip( IDF_ALL, pClipDoc, PASTE_NOFUNC, false, false, true ); // als Link - - delete pClipDoc; + PasteFromClip( IDF_ALL, pClipDoc.get(), PASTE_NOFUNC, false, false, true ); // als Link return true; } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits