summaryrefslogtreecommitdiff
path: root/filter
diff options
context:
space:
mode:
authorTakeshi Abe <tabe@fixedpoint.jp>2014-04-10 17:14:06 +0900
committerTakeshi Abe <tabe@fixedpoint.jp>2014-04-11 09:55:01 +0900
commit896cacf059005e254f7d502a353f4cca74f9832e (patch)
tree8314ffbc29100c2c9882cbf16ed2bb87f2fb454a /filter
parentb15666fd7582729c75bd0dd1bd0cb5d7c5a77f0c (diff)
Avoid possible memory leaks in case of exceptions
Change-Id: I43cce6b6c41582a65ff7e59de9a107b30cf8b1e8
Diffstat (limited to 'filter')
-rw-r--r--filter/source/flash/swfexporter.cxx8
-rw-r--r--filter/source/graphicfilter/eps/eps.cxx6
-rw-r--r--filter/source/graphicfilter/icgm/cgm.cxx9
-rw-r--r--filter/source/graphicfilter/idxf/dxfreprd.cxx7
-rw-r--r--filter/source/msfilter/escherex.cxx23
-rw-r--r--filter/source/msfilter/msdffimp.cxx15
6 files changed, 26 insertions, 42 deletions
diff --git a/filter/source/flash/swfexporter.cxx b/filter/source/flash/swfexporter.cxx
index 26c8197d891c..9f24474ee246 100644
--- a/filter/source/flash/swfexporter.cxx
+++ b/filter/source/flash/swfexporter.cxx
@@ -36,6 +36,7 @@
#include <vcl/wmf.hxx>
#include <vcl/graphicfilter.hxx>
#include <vcl/gdimetafiletools.hxx>
+#include <boost/scoped_ptr.hpp>
#include "swfexporter.hxx"
#include "swfwriter.hxx"
@@ -601,7 +602,7 @@ void FlashExporter::exportShape( const Reference< XShape >& xShape, bool bMaster
com::sun::star::awt::Rectangle aBoundRect;
xPropSet->getPropertyValue( "BoundRect" ) >>= aBoundRect;
- ShapeInfo* pShapeInfo = new ShapeInfo();
+ boost::scoped_ptr<ShapeInfo> pShapeInfo(new ShapeInfo());
pShapeInfo->mnX = aBoundRect.X;
pShapeInfo->mnY = aBoundRect.Y;
pShapeInfo->mnWidth = aBoundRect.Width;
@@ -651,18 +652,13 @@ void FlashExporter::exportShape( const Reference< XShape >& xShape, bool bMaster
}
if (!nID)
- {
- delete pShapeInfo;
return;
- }
pShapeInfo->mnID = nID;
// pPageInfo->addShape( pShapeInfo );
mpWriter->placeShape( pShapeInfo->mnID, _uInt16(nPlaceDepth++), pShapeInfo->mnX, pShapeInfo->mnY );
-
- delete pShapeInfo;
}
catch( const Exception& )
{
diff --git a/filter/source/graphicfilter/eps/eps.cxx b/filter/source/graphicfilter/eps/eps.cxx
index a385f1897c72..be8dcd892cad 100644
--- a/filter/source/graphicfilter/eps/eps.cxx
+++ b/filter/source/graphicfilter/eps/eps.cxx
@@ -40,6 +40,7 @@
#include "strings.hrc"
#include <math.h>
+#include <boost/scoped_ptr.hpp>
using namespace ::com::sun::star::uno;
@@ -343,9 +344,7 @@ sal_Bool PSWriter::WritePS( const Graphic& rGraphic, SvStream& rTargetStream, Fi
// try to get the dialog selection
if ( pFilterConfigItem )
{
- ResMgr* pResMgr;
-
- pResMgr = ResMgr::CreateResMgr( "eps", Application::GetSettings().GetUILanguageTag() );
+ boost::scoped_ptr<ResMgr> pResMgr(ResMgr::CreateResMgr( "eps", Application::GetSettings().GetUILanguageTag() ));
if( pResMgr )
{
@@ -366,7 +365,6 @@ sal_Bool PSWriter::WritePS( const Graphic& rGraphic, SvStream& rTargetStream, Fi
mnTextMode = pFilterConfigItem->ReadInt32( "TextMode", 0 );
if ( mnTextMode > 2 )
mnTextMode = 0;
- delete pResMgr;
}
}
diff --git a/filter/source/graphicfilter/icgm/cgm.cxx b/filter/source/graphicfilter/icgm/cgm.cxx
index 08e81ad258d7..cc3205c527b2 100644
--- a/filter/source/graphicfilter/icgm/cgm.cxx
+++ b/filter/source/graphicfilter/icgm/cgm.cxx
@@ -28,6 +28,7 @@
#include <main.hxx>
#include <elements.hxx>
#include <outact.hxx>
+#include <boost/scoped_ptr.hpp>
using namespace ::com::sun::star;
@@ -707,16 +708,14 @@ ImportCGM( OUString& rFileName, uno::Reference< frame::XModel > & rXModel, sal_u
if( rXModel.is() )
{
- CGM* pCGM= NULL;
-
try
{
- pCGM = new CGM( nMode, rXModel );
+ boost::scoped_ptr<CGM> pCGM(new CGM( nMode, rXModel ));
if ( pCGM && pCGM->IsValid() )
{
if ( nMode & CGM_IMPORT_CGM )
{
- SvStream* pIn = ::utl::UcbStreamHelper::CreateStream( rFileName, STREAM_READ );
+ boost::scoped_ptr<SvStream> pIn(::utl::UcbStreamHelper::CreateStream( rFileName, STREAM_READ ));
if ( pIn )
{
pIn->SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN );
@@ -763,7 +762,6 @@ ImportCGM( OUString& rFileName, uno::Reference< frame::XModel > & rXModel, sal_u
if ( bProgressBar )
aXStatInd->end();
#endif
- delete pIn;
}
}
}
@@ -772,7 +770,6 @@ ImportCGM( OUString& rFileName, uno::Reference< frame::XModel > & rXModel, sal_u
{
nStatus = 0;
}
- delete pCGM;
}
return nStatus;
}
diff --git a/filter/source/graphicfilter/idxf/dxfreprd.cxx b/filter/source/graphicfilter/idxf/dxfreprd.cxx
index 3ed02322f688..47cd94aa7547 100644
--- a/filter/source/graphicfilter/idxf/dxfreprd.cxx
+++ b/filter/source/graphicfilter/idxf/dxfreprd.cxx
@@ -20,7 +20,7 @@
#include <string.h>
#include <dxfreprd.hxx>
-
+#include <boost/scoped_ptr.hpp>
//------------------DXFBoundingBox--------------------------------------------
@@ -141,14 +141,13 @@ DXFRepresentation::~DXFRepresentation()
sal_Bool DXFRepresentation::Read( SvStream & rIStream, sal_uInt16 nMinPercent, sal_uInt16 nMaxPercent)
{
- DXFGroupReader * pDGR;
sal_Bool bRes;
aTables.Clear();
aBlocks.Clear();
aEntities.Clear();
- pDGR = new DXFGroupReader( rIStream, nMinPercent, nMaxPercent );
+ boost::scoped_ptr<DXFGroupReader> pDGR(new DXFGroupReader( rIStream, nMinPercent, nMaxPercent ));
pDGR->Read();
while (pDGR->GetG()!=0 || strcmp(pDGR->GetS(),"EOF")!=0) {
@@ -168,7 +167,7 @@ sal_Bool DXFRepresentation::Read( SvStream & rIStream, sal_uInt16 nMinPercent, s
bRes=pDGR->GetStatus();
- delete pDGR;
+ pDGR.reset();
if (bRes==sal_True && aBoundingBox.bEmpty==sal_True)
CalcBoundingBox(aEntities,aBoundingBox);
diff --git a/filter/source/msfilter/escherex.cxx b/filter/source/msfilter/escherex.cxx
index 89892333425f..92c4b59bab2b 100644
--- a/filter/source/msfilter/escherex.cxx
+++ b/filter/source/msfilter/escherex.cxx
@@ -91,6 +91,7 @@
#include <rtl/crc.h>
#include <rtl/strbuf.hxx>
#include <boost/scoped_array.hpp>
+#include <boost/scoped_ptr.hpp>
using namespace ::rtl;
using namespace ::com::sun::star;
@@ -1298,21 +1299,20 @@ bool EscherPropertyContainer::CreateGraphicProperties( const ::com::sun::star::u
if ( pGraphicProvider && pPicOutStrm && pShapeBoundRect && aXPropSet.is() )
{
::com::sun::star::uno::Any aAny;
- ::com::sun::star::awt::Rectangle* pVisArea = NULL;
+ boost::scoped_ptr< ::com::sun::star::awt::Rectangle> pVisArea;
if ( EscherPropertyValueHelper::GetPropertyValue( aAny, aXPropSet, OUString("VisibleArea" ) ) )
{
- pVisArea = new ::com::sun::star::awt::Rectangle;
+ pVisArea.reset(new ::com::sun::star::awt::Rectangle);
aAny >>= (*pVisArea);
}
Rectangle aRect( Point( 0, 0 ), pShapeBoundRect->GetSize() );
- sal_uInt32 nBlibId = pGraphicProvider->GetBlibID( *pPicOutStrm, aUniqueId, aRect, pVisArea, NULL );
+ sal_uInt32 nBlibId = pGraphicProvider->GetBlibID( *pPicOutStrm, aUniqueId, aRect, pVisArea.get(), NULL );
if ( nBlibId )
{
AddOpt( ESCHER_Prop_pib, nBlibId, true );
ImplCreateGraphicAttributes( aXPropSet, nBlibId, false );
bRetValue = true;
}
- delete pVisArea;
}
}
return bRetValue;
@@ -1434,7 +1434,7 @@ bool EscherPropertyContainer::CreateGraphicProperties(
sal_Bool bMirrored = sal_False;
sal_Bool bRotate = sal_True;
- GraphicAttr* pGraphicAttr = NULL;
+ boost::scoped_ptr<GraphicAttr> pGraphicAttr;
GraphicObject aGraphicObject;
OUString aGraphicUrl;
OString aUniqueId;
@@ -1600,8 +1600,8 @@ bool EscherPropertyContainer::CreateGraphicProperties(
nFormat != GFF_WMF &&
nFormat != GFF_EMF) )
{
- SvStream* pIn = ::utl::UcbStreamHelper::CreateStream(
- aTmp.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ );
+ boost::scoped_ptr<SvStream> pIn(::utl::UcbStreamHelper::CreateStream(
+ aTmp.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ ));
if ( pIn )
{
Graphic aGraphic;
@@ -1614,7 +1614,6 @@ bool EscherPropertyContainer::CreateGraphicProperties(
aUniqueId = aGraphicObject.GetUniqueID();
}
// else: simply keep the graphic link
- delete pIn;
}
}
if ( aUniqueId.isEmpty() )
@@ -1639,7 +1638,7 @@ bool EscherPropertyContainer::CreateGraphicProperties(
{
if(bMirrored || nTransparency || nRed || nGreen || nBlue || (1.0 != fGamma))
{
- pGraphicAttr = new GraphicAttr;
+ pGraphicAttr.reset(new GraphicAttr);
if(bMirrored)
{
@@ -1719,7 +1718,7 @@ bool EscherPropertyContainer::CreateGraphicProperties(
if ( pGraphicProvider && pPicOutStrm && pShapeBoundRect )
{
Rectangle aRect( Point( 0, 0 ), pShapeBoundRect->GetSize() );
- const sal_uInt32 nBlibId(pGraphicProvider->GetBlibID(*pPicOutStrm, aUniqueId, aRect, NULL, pGraphicAttr));
+ const sal_uInt32 nBlibId(pGraphicProvider->GetBlibID(*pPicOutStrm, aUniqueId, aRect, NULL, pGraphicAttr.get()));
if(nBlibId)
{
@@ -1742,7 +1741,7 @@ bool EscherPropertyContainer::CreateGraphicProperties(
SvMemoryStream aMemStrm;
Rectangle aRect;
- if ( aProvider.GetBlibID( aMemStrm, aUniqueId, aRect, NULL, pGraphicAttr, bOOxmlExport ) )
+ if ( aProvider.GetBlibID( aMemStrm, aUniqueId, aRect, NULL, pGraphicAttr.get(), bOOxmlExport ) )
{
// grab BLIP from stream and insert directly as complex property
// ownership of stream memory goes to complex property
@@ -1767,7 +1766,7 @@ bool EscherPropertyContainer::CreateGraphicProperties(
}
}
}
- delete pGraphicAttr;
+ pGraphicAttr.reset();
if ( bCreateFillStyles )
CreateFillProperties( rXPropSet, true );
diff --git a/filter/source/msfilter/msdffimp.cxx b/filter/source/msfilter/msdffimp.cxx
index 2622b0fd2946..2323f8b55169 100644
--- a/filter/source/msfilter/msdffimp.cxx
+++ b/filter/source/msfilter/msdffimp.cxx
@@ -255,7 +255,7 @@ void DffPropertyReader::ReadPropSet( SvStream& rIn, void* pClientData ) const
if( ::utl::LocalFileHelper::ConvertPhysicalNameToURL( OUString("d:\\ashape.dbg"), aURLStr ) )
{
- SvStream* pOut = ::utl::UcbStreamHelper::CreateStream( aURLStr, STREAM_WRITE );
+ boost::scoped_ptr<SvStream> pOut(::utl::UcbStreamHelper::CreateStream( aURLStr, STREAM_WRITE ));
if( pOut )
{
@@ -339,8 +339,6 @@ void DffPropertyReader::ReadPropSet( SvStream& rIn, void* pClientData ) const
}
}
}
-
- delete pOut;
}
}
@@ -6302,10 +6300,10 @@ bool SvxMSDffManager::GetBLIPDirect( SvStream& rBLIPStream, Graphic& rData, Rect
rBLIPStream.SeekRel( nSkip );
SvStream* pGrStream = &rBLIPStream;
- SvMemoryStream* pOut = NULL;
+ boost::scoped_ptr<SvMemoryStream> pOut;
if( bZCodecCompression )
{
- pOut = new SvMemoryStream( 0x8000, 0x4000 );
+ pOut.reset(new SvMemoryStream( 0x8000, 0x4000 ));
ZCodec aZCodec( 0x8000, 0x8000 );
aZCodec.BeginCompression();
aZCodec.Decompress( rBLIPStream, *pOut );
@@ -6313,7 +6311,7 @@ bool SvxMSDffManager::GetBLIPDirect( SvStream& rBLIPStream, Graphic& rData, Rect
pOut->Seek( STREAM_SEEK_TO_BEGIN );
pOut->SetResizeOffset( 0 ); // sj: #i102257# setting ResizeOffset of 0 prevents from seeking
// behind the stream end (allocating too much memory)
- pGrStream = pOut;
+ pGrStream = pOut.get();
}
#if OSL_DEBUG_LEVEL > 2
@@ -6345,7 +6343,7 @@ bool SvxMSDffManager::GetBLIPDirect( SvStream& rBLIPStream, Graphic& rData, Rect
SAL_INFO("filter.ms", "dumping " << aURLStr);
- SvStream* pDbgOut = ::utl::UcbStreamHelper::CreateStream(aURLStr, STREAM_TRUNC | STREAM_WRITE);
+ boost::scoped_ptr<SvStream> pDbgOut(::utl::UcbStreamHelper::CreateStream(aURLStr, STREAM_TRUNC | STREAM_WRITE));
if( pDbgOut )
{
@@ -6366,8 +6364,6 @@ bool SvxMSDffManager::GetBLIPDirect( SvStream& rBLIPStream, Graphic& rData, Rect
pGrStream->SeekRel( -nDbgLen );
}
}
-
- delete pDbgOut;
}
}
#endif
@@ -6415,7 +6411,6 @@ bool SvxMSDffManager::GetBLIPDirect( SvStream& rBLIPStream, Graphic& rData, Rect
// reset error status if necessary
if ( ERRCODE_IO_PENDING == pGrStream->GetError() )
pGrStream->ResetError();
- delete pOut;
}
rBLIPStream.Seek( nOldPos ); // restore old FilePos of the strem