diff options
author | Takeshi Abe <tabe@fixedpoint.jp> | 2014-06-30 11:33:26 +0900 |
---|---|---|
committer | Takeshi Abe <tabe@fixedpoint.jp> | 2014-06-30 11:44:16 +0900 |
commit | b20e6acea2cb2013f450bb4b97b51142dbb4f161 (patch) | |
tree | e441dfb4fdca68c9c0cd2f76cbf955d93b0a74d8 /svx | |
parent | d4feafb064560f27fce8ed3e760325545e7ba539 (diff) |
Avoid possible memory leaks in case of exceptions
Change-Id: I9a92edd7886db484f1333585545f6f63a233a6dd
Diffstat (limited to 'svx')
-rw-r--r-- | svx/source/svdraw/svdmodel.cxx | 25 | ||||
-rw-r--r-- | svx/source/svdraw/svdobj.cxx | 6 | ||||
-rw-r--r-- | svx/source/svdraw/svdograf.cxx | 9 | ||||
-rw-r--r-- | svx/source/svdraw/svdotxln.cxx | 6 | ||||
-rw-r--r-- | svx/source/svdraw/svdtext.cxx | 5 | ||||
-rw-r--r-- | svx/source/table/tablecontroller.cxx | 5 | ||||
-rw-r--r-- | svx/source/table/tablertfimporter.cxx | 4 |
7 files changed, 29 insertions, 31 deletions
diff --git a/svx/source/svdraw/svdmodel.cxx b/svx/source/svdraw/svdmodel.cxx index dac12e7a6341..7ea96c3daf80 100644 --- a/svx/source/svdraw/svdmodel.cxx +++ b/svx/source/svdraw/svdmodel.cxx @@ -86,6 +86,7 @@ #include <svl/itemset.hxx> #include <vcl/settings.hxx> #include <vcl/svapp.hxx> +#include <boost/scoped_array.hpp> using namespace ::com::sun::star; using namespace ::com::sun::star::uno; @@ -1538,7 +1539,7 @@ void SdrModel::CopyPages(sal_uInt16 nFirstPageNum, sal_uInt16 nLastPageNum, // at first, save the pointers of the affected pages in an array sal_uInt16 nPageNum=nFirstPageNum; sal_uInt16 nCopyAnz=((!bReverse)?(nLastPageNum-nFirstPageNum):(nFirstPageNum-nLastPageNum))+1; - SdrPage** pPagePtrs=new SdrPage*[nCopyAnz]; + boost::scoped_array<SdrPage*> pPagePtrs(new SdrPage*[nCopyAnz]); sal_uInt16 nCopyNum; for(nCopyNum=0; nCopyNum<nCopyAnz; nCopyNum++) { @@ -1584,7 +1585,7 @@ void SdrModel::CopyPages(sal_uInt16 nFirstPageNum, sal_uInt16 nLastPageNum, nPageNum2++; } - delete[] pPagePtrs; + pPagePtrs.reset(); if(bUndo) EndUndo(); } @@ -1616,18 +1617,18 @@ void SdrModel::Merge(SdrModel& rSourceModel, if (nLastPageNum>nMaxSrcPage) nLastPageNum =nMaxSrcPage; bool bReverse=nLastPageNum<nFirstPageNum; - sal_uInt16* pMasterMap=NULL; - bool* pMasterNeed=NULL; + boost::scoped_array<sal_uInt16> pMasterMap; + boost::scoped_array<bool> pMasterNeed; sal_uInt16 nMasterNeed=0; if (bMergeMasterPages && nSrcMasterPageAnz!=0) { // determine which MasterPages from rSrcModel we need - pMasterMap=new sal_uInt16[nSrcMasterPageAnz]; - pMasterNeed=new bool[nSrcMasterPageAnz]; - memset(pMasterMap,0xFF,nSrcMasterPageAnz*sizeof(sal_uInt16)); + pMasterMap.reset(new sal_uInt16[nSrcMasterPageAnz]); + pMasterNeed.reset(new bool[nSrcMasterPageAnz]); + memset(pMasterMap.get(),0xFF,nSrcMasterPageAnz*sizeof(sal_uInt16)); if (bAllMasterPages) { - memset(pMasterNeed, true, nSrcMasterPageAnz * sizeof(bool)); + memset(pMasterNeed.get(), true, nSrcMasterPageAnz * sizeof(bool)); } else { - memset(pMasterNeed, false, nSrcMasterPageAnz * sizeof(bool)); + memset(pMasterNeed.get(), false, nSrcMasterPageAnz * sizeof(bool)); sal_uInt16 nAnf= bReverse ? nLastPageNum : nFirstPageNum; sal_uInt16 nEnd= bReverse ? nFirstPageNum : nLastPageNum; for (sal_uInt16 i=nAnf; i<=nEnd; i++) { @@ -1656,7 +1657,7 @@ void SdrModel::Merge(SdrModel& rSourceModel, } // get the MasterPages - if (pMasterMap!=NULL && pMasterNeed!=NULL && nMasterNeed!=0) { + if (pMasterMap && pMasterNeed && nMasterNeed!=0) { for (sal_uInt16 i=nSrcMasterPageAnz; i>0;) { i--; if (pMasterNeed[i]) { @@ -1743,8 +1744,8 @@ void SdrModel::Merge(SdrModel& rSourceModel, } } - delete [] pMasterMap; - delete [] pMasterNeed; + pMasterMap.reset(); + pMasterNeed.reset(); bMPgNumsDirty=true; bPagNumsDirty=true; diff --git a/svx/source/svdraw/svdobj.cxx b/svx/source/svdraw/svdobj.cxx index a5fd48ae757d..dea52a782230 100644 --- a/svx/source/svdraw/svdobj.cxx +++ b/svx/source/svdraw/svdobj.cxx @@ -129,6 +129,7 @@ #include <svx/xpoly.hxx> #include <rtl/strbuf.hxx> #include <svdoopengl.hxx> +#include <boost/scoped_ptr.hpp> using namespace ::com::sun::star; @@ -3315,16 +3316,15 @@ SdrObject* SdrObjFactory::MakeNewObject(sal_uInt32 nInvent, sal_uInt16 nIdent, S if(pObj == NULL) { - SdrObjFactory* pFact=new SdrObjFactory(nInvent,nIdent,pPage,pModel); + boost::scoped_ptr<SdrObjFactory> pFact(new SdrObjFactory(nInvent,nIdent,pPage,pModel)); SdrLinkList& rLL=ImpGetUserMakeObjHdl(); unsigned nAnz=rLL.GetLinkCount(); unsigned i=0; while (i<nAnz && pObj==NULL) { - rLL.GetLink(i).Call((void*)pFact); + rLL.GetLink(i).Call((void*)pFact.get()); pObj=pFact->pNewObj; i++; } - delete pFact; } if(pObj == NULL) diff --git a/svx/source/svdraw/svdograf.cxx b/svx/source/svdraw/svdograf.cxx index 75e8b470a813..54776a56598d 100644 --- a/svx/source/svdraw/svdograf.cxx +++ b/svx/source/svdraw/svdograf.cxx @@ -61,6 +61,7 @@ #include <osl/thread.hxx> #include <drawinglayer/processor2d/objectinfoextractor2d.hxx> #include <drawinglayer/primitive2d/objectinfoprimitive2d.hxx> +#include <boost/scoped_ptr.hpp> using namespace ::com::sun::star; using namespace ::com::sun::star::uno; @@ -1334,11 +1335,11 @@ IMPL_LINK( SdrGrafObj, ImpSwapHdl, GraphicObject*, pO ) { Graphic aGraphic; - com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >* pFilterData = NULL; + boost::scoped_ptr<com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > > pFilterData; if(mbInsidePaint && !GetViewContact().HasViewObjectContacts(true)) { - pFilterData = new com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >( 3 ); + pFilterData.reset(new com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >( 3 )); const com::sun::star::awt::Size aPreviewSizeHint( 64, 64 ); const bool bAllowPartialStreamRead = true; @@ -1357,7 +1358,7 @@ IMPL_LINK( SdrGrafObj, ImpSwapHdl, GraphicObject*, pO ) if(!GraphicFilter::GetGraphicFilter().ImportGraphic( aGraphic, aUserData, *pStream, - GRFILTER_FORMAT_DONTKNOW, NULL, 0, pFilterData)) + GRFILTER_FORMAT_DONTKNOW, NULL, 0, pFilterData.get())) { const OUString aNewUserData( pGraphic->GetUserData() ); @@ -1367,7 +1368,7 @@ IMPL_LINK( SdrGrafObj, ImpSwapHdl, GraphicObject*, pO ) // Graphic successfully swapped in. pRet = GRFMGR_AUTOSWAPSTREAM_LOADED; } - delete pFilterData; + pFilterData.reset(); pStream->ResetError(); } diff --git a/svx/source/svdraw/svdotxln.cxx b/svx/source/svdraw/svdotxln.cxx index b4e386f83e56..1cc6bc406036 100644 --- a/svx/source/svdraw/svdotxln.cxx +++ b/svx/source/svdraw/svdotxln.cxx @@ -33,7 +33,7 @@ #include <tools/urlobj.hxx> #include <svl/urihelper.hxx> #include <tools/tenccvt.hxx> - +#include <boost/scoped_ptr.hpp> class ImpSdrObjTextLink: public ::sfx2::SvBaseLink { @@ -222,7 +222,7 @@ bool SdrTextObj::LoadText(const OUString& rFileName, const OUString& /*rFilterNa DBG_ASSERT( aFileURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" ); - SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( aFileURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ ); + boost::scoped_ptr<SvStream> pIStm(::utl::UcbStreamHelper::CreateStream( aFileURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ )); if( pIStm ) { @@ -241,8 +241,6 @@ bool SdrTextObj::LoadText(const OUString& rFileName, const OUString& /*rFilterNa SetText( *pIStm, aFileURL.GetMainURL( INetURLObject::NO_DECODE ), sal::static_int_cast< sal_uInt16 >( bRTF ? EE_FORMAT_RTF : EE_FORMAT_TEXT ) ); bRet = true; } - - delete pIStm; } return bRet; diff --git a/svx/source/svdraw/svdtext.cxx b/svx/source/svdraw/svdtext.cxx index 33729927360f..0dc5081a0165 100644 --- a/svx/source/svdraw/svdtext.cxx +++ b/svx/source/svdraw/svdtext.cxx @@ -25,6 +25,7 @@ #include "editeng/fhgtitem.hxx" #include <editeng/eeitem.hxx> #include <svl/itemset.hxx> +#include <boost/scoped_ptr.hpp> SdrText::SdrText( SdrTextObj& rObject, OutlinerParaObject* pOutlinerParaObject /* = 0 */ ) : mpOutlinerParaObject( pOutlinerParaObject ) @@ -172,7 +173,7 @@ void SdrText::ForceOutlinerParaObject( sal_uInt16 nOutlMode ) { if( mpModel && !mpOutlinerParaObject ) { - Outliner* pOutliner = SdrMakeOutliner( nOutlMode, mpModel ); + boost::scoped_ptr<Outliner> pOutliner(SdrMakeOutliner( nOutlMode, mpModel )); if( pOutliner ) { Outliner& aDrawOutliner = mpModel->GetDrawOutliner(); @@ -181,8 +182,6 @@ void SdrText::ForceOutlinerParaObject( sal_uInt16 nOutlMode ) pOutliner->SetStyleSheet( 0, GetStyleSheet()); OutlinerParaObject* pOutlinerParaObject = pOutliner->CreateParaObject(); SetOutlinerParaObject( pOutlinerParaObject ); - - delete pOutliner; } } } diff --git a/svx/source/table/tablecontroller.cxx b/svx/source/table/tablecontroller.cxx index 86c4f95649d4..4404c4709abe 100644 --- a/svx/source/table/tablecontroller.cxx +++ b/svx/source/table/tablecontroller.cxx @@ -397,7 +397,7 @@ void SvxTableController::GetState( SfxItemSet& rSet ) if( !mxTable.is() || !mxTableObj.is() || !mxTableObj->GetModel() ) return; - SfxItemSet* pSet = 0; + boost::scoped_ptr<SfxItemSet> pSet; bool bVertDone = false; @@ -420,7 +420,7 @@ void SvxTableController::GetState( SfxItemSet& rSet ) { if( !pSet ) { - pSet = new SfxItemSet( mxTableObj->GetModel()->GetItemPool() ); + pSet.reset(new SfxItemSet( mxTableObj->GetModel()->GetItemPool() )); MergeAttrFromSelectedCells(*pSet, false); } @@ -487,7 +487,6 @@ void SvxTableController::GetState( SfxItemSet& rSet ) } nWhich = aIter.NextWhich(); } - delete pSet; } diff --git a/svx/source/table/tablertfimporter.cxx b/svx/source/table/tablertfimporter.cxx index 2e93278b70d1..fa7b635d7133 100644 --- a/svx/source/table/tablertfimporter.cxx +++ b/svx/source/table/tablertfimporter.cxx @@ -19,6 +19,7 @@ #include <vector> +#include <boost/scoped_ptr.hpp> #include <boost/shared_ptr.hpp> #include <com/sun/star/table/XTable.hpp> @@ -272,14 +273,13 @@ void SdrTableRTFParser::FillTable() if( xCellInfo->maItemSet.GetItemState(SDRATTR_TABLE_BORDER,false,&pPoolItem)==SFX_ITEM_SET) xCell->SetMergedItem( *pPoolItem ); - OutlinerParaObject* pTextObject = mpOutliner->CreateParaObject( xCellInfo->mnStartPara, xCellInfo->mnParaCount ); + boost::scoped_ptr<OutlinerParaObject> pTextObject(mpOutliner->CreateParaObject( xCellInfo->mnStartPara, xCellInfo->mnParaCount )); if( pTextObject ) { SdrOutliner& rOutliner=mrTableObj.ImpGetDrawOutliner(); rOutliner.SetUpdateMode(true); rOutliner.SetText( *pTextObject ); mrTableObj.NbcSetOutlinerParaObjectForText( rOutliner.CreateParaObject(), xCell.get() ); - delete pTextObject; } } } |