Avoid possible memory leaks in case of exceptions

Change-Id: I9a92edd7886db484f1333585545f6f63a233a6dd
This commit is contained in:
Takeshi Abe
2014-06-30 11:33:26 +09:00
parent d4feafb064
commit b20e6acea2
7 changed files with 29 additions and 31 deletions

View File

@@ -86,6 +86,7 @@
#include <svl/itemset.hxx> #include <svl/itemset.hxx>
#include <vcl/settings.hxx> #include <vcl/settings.hxx>
#include <vcl/svapp.hxx> #include <vcl/svapp.hxx>
#include <boost/scoped_array.hpp>
using namespace ::com::sun::star; using namespace ::com::sun::star;
using namespace ::com::sun::star::uno; 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 // at first, save the pointers of the affected pages in an array
sal_uInt16 nPageNum=nFirstPageNum; sal_uInt16 nPageNum=nFirstPageNum;
sal_uInt16 nCopyAnz=((!bReverse)?(nLastPageNum-nFirstPageNum):(nFirstPageNum-nLastPageNum))+1; 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; sal_uInt16 nCopyNum;
for(nCopyNum=0; nCopyNum<nCopyAnz; nCopyNum++) for(nCopyNum=0; nCopyNum<nCopyAnz; nCopyNum++)
{ {
@@ -1584,7 +1585,7 @@ void SdrModel::CopyPages(sal_uInt16 nFirstPageNum, sal_uInt16 nLastPageNum,
nPageNum2++; nPageNum2++;
} }
delete[] pPagePtrs; pPagePtrs.reset();
if(bUndo) if(bUndo)
EndUndo(); EndUndo();
} }
@@ -1616,18 +1617,18 @@ void SdrModel::Merge(SdrModel& rSourceModel,
if (nLastPageNum>nMaxSrcPage) nLastPageNum =nMaxSrcPage; if (nLastPageNum>nMaxSrcPage) nLastPageNum =nMaxSrcPage;
bool bReverse=nLastPageNum<nFirstPageNum; bool bReverse=nLastPageNum<nFirstPageNum;
sal_uInt16* pMasterMap=NULL; boost::scoped_array<sal_uInt16> pMasterMap;
bool* pMasterNeed=NULL; boost::scoped_array<bool> pMasterNeed;
sal_uInt16 nMasterNeed=0; sal_uInt16 nMasterNeed=0;
if (bMergeMasterPages && nSrcMasterPageAnz!=0) { if (bMergeMasterPages && nSrcMasterPageAnz!=0) {
// determine which MasterPages from rSrcModel we need // determine which MasterPages from rSrcModel we need
pMasterMap=new sal_uInt16[nSrcMasterPageAnz]; pMasterMap.reset(new sal_uInt16[nSrcMasterPageAnz]);
pMasterNeed=new bool[nSrcMasterPageAnz]; pMasterNeed.reset(new bool[nSrcMasterPageAnz]);
memset(pMasterMap,0xFF,nSrcMasterPageAnz*sizeof(sal_uInt16)); memset(pMasterMap.get(),0xFF,nSrcMasterPageAnz*sizeof(sal_uInt16));
if (bAllMasterPages) { if (bAllMasterPages) {
memset(pMasterNeed, true, nSrcMasterPageAnz * sizeof(bool)); memset(pMasterNeed.get(), true, nSrcMasterPageAnz * sizeof(bool));
} else { } else {
memset(pMasterNeed, false, nSrcMasterPageAnz * sizeof(bool)); memset(pMasterNeed.get(), false, nSrcMasterPageAnz * sizeof(bool));
sal_uInt16 nAnf= bReverse ? nLastPageNum : nFirstPageNum; sal_uInt16 nAnf= bReverse ? nLastPageNum : nFirstPageNum;
sal_uInt16 nEnd= bReverse ? nFirstPageNum : nLastPageNum; sal_uInt16 nEnd= bReverse ? nFirstPageNum : nLastPageNum;
for (sal_uInt16 i=nAnf; i<=nEnd; i++) { for (sal_uInt16 i=nAnf; i<=nEnd; i++) {
@@ -1656,7 +1657,7 @@ void SdrModel::Merge(SdrModel& rSourceModel,
} }
// get the MasterPages // get the MasterPages
if (pMasterMap!=NULL && pMasterNeed!=NULL && nMasterNeed!=0) { if (pMasterMap && pMasterNeed && nMasterNeed!=0) {
for (sal_uInt16 i=nSrcMasterPageAnz; i>0;) { for (sal_uInt16 i=nSrcMasterPageAnz; i>0;) {
i--; i--;
if (pMasterNeed[i]) { if (pMasterNeed[i]) {
@@ -1743,8 +1744,8 @@ void SdrModel::Merge(SdrModel& rSourceModel,
} }
} }
delete [] pMasterMap; pMasterMap.reset();
delete [] pMasterNeed; pMasterNeed.reset();
bMPgNumsDirty=true; bMPgNumsDirty=true;
bPagNumsDirty=true; bPagNumsDirty=true;

View File

@@ -129,6 +129,7 @@
#include <svx/xpoly.hxx> #include <svx/xpoly.hxx>
#include <rtl/strbuf.hxx> #include <rtl/strbuf.hxx>
#include <svdoopengl.hxx> #include <svdoopengl.hxx>
#include <boost/scoped_ptr.hpp>
using namespace ::com::sun::star; using namespace ::com::sun::star;
@@ -3315,16 +3316,15 @@ SdrObject* SdrObjFactory::MakeNewObject(sal_uInt32 nInvent, sal_uInt16 nIdent, S
if(pObj == NULL) 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(); SdrLinkList& rLL=ImpGetUserMakeObjHdl();
unsigned nAnz=rLL.GetLinkCount(); unsigned nAnz=rLL.GetLinkCount();
unsigned i=0; unsigned i=0;
while (i<nAnz && pObj==NULL) { while (i<nAnz && pObj==NULL) {
rLL.GetLink(i).Call((void*)pFact); rLL.GetLink(i).Call((void*)pFact.get());
pObj=pFact->pNewObj; pObj=pFact->pNewObj;
i++; i++;
} }
delete pFact;
} }
if(pObj == NULL) if(pObj == NULL)

View File

@@ -61,6 +61,7 @@
#include <osl/thread.hxx> #include <osl/thread.hxx>
#include <drawinglayer/processor2d/objectinfoextractor2d.hxx> #include <drawinglayer/processor2d/objectinfoextractor2d.hxx>
#include <drawinglayer/primitive2d/objectinfoprimitive2d.hxx> #include <drawinglayer/primitive2d/objectinfoprimitive2d.hxx>
#include <boost/scoped_ptr.hpp>
using namespace ::com::sun::star; using namespace ::com::sun::star;
using namespace ::com::sun::star::uno; using namespace ::com::sun::star::uno;
@@ -1334,11 +1335,11 @@ IMPL_LINK( SdrGrafObj, ImpSwapHdl, GraphicObject*, pO )
{ {
Graphic aGraphic; 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)) 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 com::sun::star::awt::Size aPreviewSizeHint( 64, 64 );
const bool bAllowPartialStreamRead = true; const bool bAllowPartialStreamRead = true;
@@ -1357,7 +1358,7 @@ IMPL_LINK( SdrGrafObj, ImpSwapHdl, GraphicObject*, pO )
if(!GraphicFilter::GetGraphicFilter().ImportGraphic( if(!GraphicFilter::GetGraphicFilter().ImportGraphic(
aGraphic, aUserData, *pStream, aGraphic, aUserData, *pStream,
GRFILTER_FORMAT_DONTKNOW, NULL, 0, pFilterData)) GRFILTER_FORMAT_DONTKNOW, NULL, 0, pFilterData.get()))
{ {
const OUString aNewUserData( pGraphic->GetUserData() ); const OUString aNewUserData( pGraphic->GetUserData() );
@@ -1367,7 +1368,7 @@ IMPL_LINK( SdrGrafObj, ImpSwapHdl, GraphicObject*, pO )
// Graphic successfully swapped in. // Graphic successfully swapped in.
pRet = GRFMGR_AUTOSWAPSTREAM_LOADED; pRet = GRFMGR_AUTOSWAPSTREAM_LOADED;
} }
delete pFilterData; pFilterData.reset();
pStream->ResetError(); pStream->ResetError();
} }

View File

@@ -33,7 +33,7 @@
#include <tools/urlobj.hxx> #include <tools/urlobj.hxx>
#include <svl/urihelper.hxx> #include <svl/urihelper.hxx>
#include <tools/tenccvt.hxx> #include <tools/tenccvt.hxx>
#include <boost/scoped_ptr.hpp>
class ImpSdrObjTextLink: public ::sfx2::SvBaseLink 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" ); 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 ) 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 ) ); SetText( *pIStm, aFileURL.GetMainURL( INetURLObject::NO_DECODE ), sal::static_int_cast< sal_uInt16 >( bRTF ? EE_FORMAT_RTF : EE_FORMAT_TEXT ) );
bRet = true; bRet = true;
} }
delete pIStm;
} }
return bRet; return bRet;

View File

@@ -25,6 +25,7 @@
#include "editeng/fhgtitem.hxx" #include "editeng/fhgtitem.hxx"
#include <editeng/eeitem.hxx> #include <editeng/eeitem.hxx>
#include <svl/itemset.hxx> #include <svl/itemset.hxx>
#include <boost/scoped_ptr.hpp>
SdrText::SdrText( SdrTextObj& rObject, OutlinerParaObject* pOutlinerParaObject /* = 0 */ ) SdrText::SdrText( SdrTextObj& rObject, OutlinerParaObject* pOutlinerParaObject /* = 0 */ )
: mpOutlinerParaObject( pOutlinerParaObject ) : mpOutlinerParaObject( pOutlinerParaObject )
@@ -172,7 +173,7 @@ void SdrText::ForceOutlinerParaObject( sal_uInt16 nOutlMode )
{ {
if( mpModel && !mpOutlinerParaObject ) if( mpModel && !mpOutlinerParaObject )
{ {
Outliner* pOutliner = SdrMakeOutliner( nOutlMode, mpModel ); boost::scoped_ptr<Outliner> pOutliner(SdrMakeOutliner( nOutlMode, mpModel ));
if( pOutliner ) if( pOutliner )
{ {
Outliner& aDrawOutliner = mpModel->GetDrawOutliner(); Outliner& aDrawOutliner = mpModel->GetDrawOutliner();
@@ -181,8 +182,6 @@ void SdrText::ForceOutlinerParaObject( sal_uInt16 nOutlMode )
pOutliner->SetStyleSheet( 0, GetStyleSheet()); pOutliner->SetStyleSheet( 0, GetStyleSheet());
OutlinerParaObject* pOutlinerParaObject = pOutliner->CreateParaObject(); OutlinerParaObject* pOutlinerParaObject = pOutliner->CreateParaObject();
SetOutlinerParaObject( pOutlinerParaObject ); SetOutlinerParaObject( pOutlinerParaObject );
delete pOutliner;
} }
} }
} }

View File

@@ -397,7 +397,7 @@ void SvxTableController::GetState( SfxItemSet& rSet )
if( !mxTable.is() || !mxTableObj.is() || !mxTableObj->GetModel() ) if( !mxTable.is() || !mxTableObj.is() || !mxTableObj->GetModel() )
return; return;
SfxItemSet* pSet = 0; boost::scoped_ptr<SfxItemSet> pSet;
bool bVertDone = false; bool bVertDone = false;
@@ -420,7 +420,7 @@ void SvxTableController::GetState( SfxItemSet& rSet )
{ {
if( !pSet ) if( !pSet )
{ {
pSet = new SfxItemSet( mxTableObj->GetModel()->GetItemPool() ); pSet.reset(new SfxItemSet( mxTableObj->GetModel()->GetItemPool() ));
MergeAttrFromSelectedCells(*pSet, false); MergeAttrFromSelectedCells(*pSet, false);
} }
@@ -487,7 +487,6 @@ void SvxTableController::GetState( SfxItemSet& rSet )
} }
nWhich = aIter.NextWhich(); nWhich = aIter.NextWhich();
} }
delete pSet;
} }

View File

@@ -19,6 +19,7 @@
#include <vector> #include <vector>
#include <boost/scoped_ptr.hpp>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <com/sun/star/table/XTable.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) if( xCellInfo->maItemSet.GetItemState(SDRATTR_TABLE_BORDER,false,&pPoolItem)==SFX_ITEM_SET)
xCell->SetMergedItem( *pPoolItem ); xCell->SetMergedItem( *pPoolItem );
OutlinerParaObject* pTextObject = mpOutliner->CreateParaObject( xCellInfo->mnStartPara, xCellInfo->mnParaCount ); boost::scoped_ptr<OutlinerParaObject> pTextObject(mpOutliner->CreateParaObject( xCellInfo->mnStartPara, xCellInfo->mnParaCount ));
if( pTextObject ) if( pTextObject )
{ {
SdrOutliner& rOutliner=mrTableObj.ImpGetDrawOutliner(); SdrOutliner& rOutliner=mrTableObj.ImpGetDrawOutliner();
rOutliner.SetUpdateMode(true); rOutliner.SetUpdateMode(true);
rOutliner.SetText( *pTextObject ); rOutliner.SetText( *pTextObject );
mrTableObj.NbcSetOutlinerParaObjectForText( rOutliner.CreateParaObject(), xCell.get() ); mrTableObj.NbcSetOutlinerParaObjectForText( rOutliner.CreateParaObject(), xCell.get() );
delete pTextObject;
} }
} }
} }