summaryrefslogtreecommitdiff
path: root/filter
diff options
context:
space:
mode:
authorTakeshi Abe <tabe@fixedpoint.jp>2014-04-07 14:58:25 +0900
committerTakeshi Abe <tabe@fixedpoint.jp>2014-04-07 15:00:12 +0900
commit099dd432b28adbd1d0503ec688a1e9b3579aab2b (patch)
treecd653727170faae75aa803753c6c937472de3a53 /filter
parent4973486e6435fa7680b4cd7ff526b8bf6d5d08a3 (diff)
Avoid possible memory leaks in case of exceptions
Change-Id: If541e39e34490adccc8baab43ea9516c3dc6cc1a
Diffstat (limited to 'filter')
-rw-r--r--filter/source/graphicfilter/epict/epict.cxx20
-rw-r--r--filter/source/graphicfilter/icgm/bundles.cxx16
-rw-r--r--filter/source/graphicfilter/icgm/class4.cxx5
-rw-r--r--filter/source/graphicfilter/ieps/ieps.cxx15
-rw-r--r--filter/source/graphicfilter/ios2met/ios2met.cxx21
5 files changed, 36 insertions, 41 deletions
diff --git a/filter/source/graphicfilter/epict/epict.cxx b/filter/source/graphicfilter/epict/epict.cxx
index cdb5d3479e33..22b90fd2a95a 100644
--- a/filter/source/graphicfilter/epict/epict.cxx
+++ b/filter/source/graphicfilter/epict/epict.cxx
@@ -37,6 +37,7 @@
#include <basegfx/polygon/b2dpolygon.hxx>
#include <basegfx/polygon/b2dpolypolygon.hxx>
+#include <boost/scoped_array.hpp>
// PictWriter
struct PictWriterAttrStackMember {
@@ -871,7 +872,7 @@ void PictWriter::WriteOpcode_BitsRect(const Point & rPoint, const Size & rSize,
sal_uLong nWidth, nHeight, nDstRowBytes, nx, nc, ny, nCount, nColTabSize, i;
sal_uLong nDstRowPos, nSrcRowBytes, nEqu3, nPos, nDstMapPos;
sal_uInt16 nBitsPerPixel, nPackType;
- sal_uInt8 *pComp[4], *pPix, *pTemp;
+ sal_uInt8 *pComp[4], *pTemp;
sal_uInt8 nEquData = 0;
sal_uInt8 nFlagCounterByte, nRed, nGreen, nBlue;
@@ -1141,7 +1142,7 @@ void PictWriter::WriteOpcode_BitsRect(const Point & rPoint, const Size & rSize,
pPict->WriteUInt16( (sal_uInt16)0 ); // (?)
// allocate memory for a row:
- pPix = new sal_uInt8[ nSrcRowBytes ];
+ boost::scoped_array<sal_uInt8> pPix(new sal_uInt8[ nSrcRowBytes ]);
// remember position of the map-data in the target:
nDstMapPos=pPict->Tell();
@@ -1153,13 +1154,13 @@ void PictWriter::WriteOpcode_BitsRect(const Point & rPoint, const Size & rSize,
switch ( nBitsPerPixel )
{
case 1 :
- for ( pTemp = pPix, i = 0; i < nSrcRowBytes; i++ )
+ for ( pTemp = pPix.get(), i = 0; i < nSrcRowBytes; i++ )
*pTemp++ = (sal_uInt8)0;
for ( i = 0; i < nWidth; i++ )
pPix[ ( i >> 3 ) ] |= (pAcc->GetPixelIndex( ny, i ) & 1) << ((i & 7) ^ 7);
break;
case 4 :
- for ( pTemp = pPix, i = 0; i < nSrcRowBytes; i++ )
+ for ( pTemp = pPix.get(), i = 0; i < nSrcRowBytes; i++ )
*pTemp++ = (sal_uInt8)0;
for ( i = 0; i < nWidth; i++ )
pPix[ ( i >> 1 ) ] |= (pAcc->GetPixelIndex( ny, i ) & 15) << ((i & 1) << 2);
@@ -1172,7 +1173,7 @@ void PictWriter::WriteOpcode_BitsRect(const Point & rPoint, const Size & rSize,
if ( nPackType == 1 )
{ // don't pack
- pPict->Write( pPix, nDstRowBytes );
+ pPict->Write( pPix.get(), nDstRowBytes );
}
else
{ // Ppacking (nPackType==0)
@@ -1256,8 +1257,6 @@ void PictWriter::WriteOpcode_BitsRect(const Point & rPoint, const Size & rSize,
if ( pPict->GetError() )
bStatus = sal_False;
}
- // cleaning up:
- delete[] pPix;
}
// Map-Data has to be an even number of bytes:
@@ -1744,8 +1743,8 @@ void PictWriter::WriteOpcodes( const GDIMetaFile & rMTF )
Point aPt( pA->GetPoint() );
OUString aStr = pA->GetText().copy( pA->GetIndex(),pA->GetLen() );
VirtualDevice aVirDev;
- sal_Int32* pDXAry = new sal_Int32[ aStr.getLength() ];
- sal_Int32 nNormSize( aVirDev.GetTextArray( aStr,pDXAry ) );
+ boost::scoped_array<sal_Int32> pDXAry(new sal_Int32[ aStr.getLength() ]);
+ sal_Int32 nNormSize( aVirDev.GetTextArray( aStr,pDXAry.get() ) );
sal_uInt16 i;
if (aSrcFont.GetAlign()!=ALIGN_BASELINE)
@@ -1760,8 +1759,7 @@ void PictWriter::WriteOpcodes( const GDIMetaFile & rMTF )
pDXAry[ i ] = pDXAry[ i ] * ( (long)pA->GetWidth() ) / nNormSize;
SetAttrForText();
- WriteTextArray( aPt, aStr, pDXAry );
- delete[] pDXAry;
+ WriteTextArray( aPt, aStr, pDXAry.get() );
}
break;
diff --git a/filter/source/graphicfilter/icgm/bundles.cxx b/filter/source/graphicfilter/icgm/bundles.cxx
index 2b22bc40361c..bfd80459d14e 100644
--- a/filter/source/graphicfilter/icgm/bundles.cxx
+++ b/filter/source/graphicfilter/icgm/bundles.cxx
@@ -21,6 +21,7 @@
#include "bundles.hxx"
#include <tools/stream.hxx>
+#include <boost/scoped_array.hpp>
Bundle& Bundle::operator=( Bundle& rSource )
{
@@ -191,13 +192,13 @@ void CGMFList::InsertName( sal_uInt8* pSource, sal_uInt32 nSize )
pFontEntry = aFontEntryList[ nFontNameCount ];
}
nFontNameCount++;
- sal_Int8* pBuf = new sal_Int8[ nSize ];
- memcpy( pBuf, pSource, nSize );
- sal_Int8* pFound = ImplSearchEntry( pBuf, (sal_Int8*)"ITALIC", nSize, 6 );
+ boost::scoped_array<sal_Int8> pBuf(new sal_Int8[ nSize ]);
+ memcpy( pBuf.get(), pSource, nSize );
+ sal_Int8* pFound = ImplSearchEntry( pBuf.get(), (sal_Int8*)"ITALIC", nSize, 6 );
if ( pFound )
{
pFontEntry->nFontType |= 1;
- sal_uInt32 nPrev = ( pFound - pBuf );
+ sal_uInt32 nPrev = ( pFound - pBuf.get() );
sal_uInt32 nToCopyOfs = 6;
if ( nPrev && ( pFound[ -1 ] == '-' || pFound[ -1 ] == ' ' ) )
{
@@ -212,12 +213,12 @@ void CGMFList::InsertName( sal_uInt8* pSource, sal_uInt32 nSize )
}
nSize -= nToCopyOfs;
}
- pFound = ImplSearchEntry( pBuf, (sal_Int8*)"BOLD", nSize, 4 );
+ pFound = ImplSearchEntry( pBuf.get(), (sal_Int8*)"BOLD", nSize, 4 );
if ( pFound )
{
pFontEntry->nFontType |= 2;
- sal_uInt32 nPrev = ( pFound - pBuf );
+ sal_uInt32 nPrev = ( pFound - pBuf.get() );
sal_uInt32 nToCopyOfs = 4;
if ( nPrev && ( pFound[ -1 ] == '-' || pFound[ -1 ] == ' ' ) )
{
@@ -234,8 +235,7 @@ void CGMFList::InsertName( sal_uInt8* pSource, sal_uInt32 nSize )
}
pFontEntry->pFontName = new sal_Int8[ nSize + 1 ];
pFontEntry->pFontName[ nSize ] = 0;
- memcpy( pFontEntry->pFontName, pBuf, nSize );
- delete[] pBuf;
+ memcpy( pFontEntry->pFontName, pBuf.get(), nSize );
}
diff --git a/filter/source/graphicfilter/icgm/class4.cxx b/filter/source/graphicfilter/icgm/class4.cxx
index 0f99aff1b704..d92330ee4708 100644
--- a/filter/source/graphicfilter/icgm/class4.cxx
+++ b/filter/source/graphicfilter/icgm/class4.cxx
@@ -22,6 +22,7 @@
#include <chart.hxx>
#include <outact.hxx>
#include <math.h>
+#include <boost/scoped_array.hpp>
using namespace ::com::sun::star;
@@ -270,7 +271,7 @@ void CGM::ImplDoClass4()
mpOutAct->CloseRegion();
sal_uInt16 nPoints = 0;
- Point* pPoints = new Point[ 0x4000 ];
+ boost::scoped_array<Point> pPoints(new Point[ 0x4000 ]);
PolyPolygon aPolyPolygon;
FloatPoint aFloatPoint;
@@ -291,7 +292,7 @@ void CGM::ImplDoClass4()
nPoints = 0;
}
}
- delete[] pPoints;
+ pPoints.reset();
mpOutAct->DrawPolyPolygon( aPolyPolygon );
}
break;
diff --git a/filter/source/graphicfilter/ieps/ieps.cxx b/filter/source/graphicfilter/ieps/ieps.cxx
index c01feba918b0..dc22abe41da2 100644
--- a/filter/source/graphicfilter/ieps/ieps.cxx
+++ b/filter/source/graphicfilter/ieps/ieps.cxx
@@ -36,6 +36,7 @@
#include <unotools/tempfile.hxx>
#include <osl/process.h>
#include <osl/file.hxx>
+#include <boost/scoped_array.hpp>
class FilterConfigItem;
@@ -367,19 +368,17 @@ void CreateMtfReplacementAction( GDIMetaFile& rMtf, SvStream& rStrm, sal_uInt32
.WriteUInt32( nTPos ).WriteUInt32( nSizeTIFF );
if ( nSizeWMF )
{
- sal_uInt8* pBuf = new sal_uInt8[ nSizeWMF ];
+ boost::scoped_array<sal_uInt8> pBuf(new sal_uInt8[ nSizeWMF ]);
rStrm.Seek( nOrigPos + nPosWMF );
- rStrm.Read( pBuf, nSizeWMF );
- aReplacement.Write( pBuf, nSizeWMF );
- delete[] pBuf;
+ rStrm.Read( pBuf.get(), nSizeWMF );
+ aReplacement.Write( pBuf.get(), nSizeWMF );
}
if ( nSizeTIFF )
{
- sal_uInt8* pBuf = new sal_uInt8[ nSizeTIFF ];
+ boost::scoped_array<sal_uInt8> pBuf(new sal_uInt8[ nSizeTIFF ]);
rStrm.Seek( nOrigPos + nPosTIFF );
- rStrm.Read( pBuf, nSizeTIFF );
- aReplacement.Write( pBuf, nSizeTIFF );
- delete[] pBuf;
+ rStrm.Read( pBuf.get(), nSizeTIFF );
+ aReplacement.Write( pBuf.get(), nSizeTIFF );
}
rMtf.AddAction( (MetaAction*)( new MetaCommentAction( aComment, 0, (const sal_uInt8*)aReplacement.GetData(), aReplacement.Tell() ) ) );
}
diff --git a/filter/source/graphicfilter/ios2met/ios2met.cxx b/filter/source/graphicfilter/ios2met/ios2met.cxx
index e9435de6f347..e0acde9d932b 100644
--- a/filter/source/graphicfilter/ios2met/ios2met.cxx
+++ b/filter/source/graphicfilter/ios2met/ios2met.cxx
@@ -25,6 +25,7 @@
#include <vcl/lineinfo.hxx>
#include <math.h>
+#include <boost/scoped_array.hpp>
class FilterConfigItem;
@@ -944,7 +945,6 @@ void OS2METReader::ReadChrStr(sal_Bool bGivenPos, sal_Bool bMove, sal_Bool bExtr
{
Point aP0;
sal_uInt16 i, nLen;
- char * pChr;
OSFont * pF;
Font aFont;
Size aSize;
@@ -978,11 +978,11 @@ void OS2METReader::ReadChrStr(sal_Bool bGivenPos, sal_Bool bMove, sal_Bool bExtr
else
nLen = nOrderLen-4;
}
- pChr = new char[nLen+1];
+ boost::scoped_array<char> pChr(new char[nLen+1]);
for (i=0; i<nLen; i++)
pOS2MET->ReadChar( pChr[i] );
pChr[nLen] = 0;
- OUString aStr( (const sal_Char*)pChr, strlen(pChr), osl_getThreadTextEncoding() );
+ OUString aStr( (const sal_Char*)pChr.get(), strlen(pChr.get()), osl_getThreadTextEncoding() );
SetRasterOp(aAttr.eChrMix);
if (pVirDev->GetFont()!=aFont)
pVirDev->SetFont(aFont);
@@ -1010,7 +1010,6 @@ void OS2METReader::ReadChrStr(sal_Bool bGivenPos, sal_Bool bMove, sal_Bool bExtr
aCalcBndRect.Union( Rectangle( aDummyPoly.GetPoint( 0 ), aDummyPoly.GetPoint( 3 ) ) );
aCalcBndRect.Union( Rectangle( aDummyPoly.GetPoint( 1 ), aDummyPoly.GetPoint( 2 ) ) );
}
- delete[] pChr;
}
void OS2METReader::ReadArc(sal_Bool bGivenPos)
@@ -2189,8 +2188,8 @@ void OS2METReader::ReadImageData(sal_uInt16 nDataID, sal_uInt16 nDataLen)
}
// OK, now the map data is beeing pushed. Unfortunatly OS2 and BMP
// do habe a different RGB ordering when using 24-bit
- sal_uInt8 * pBuf=new sal_uInt8[nDataLen];
- pOS2MET->Read(pBuf,nDataLen);
+ boost::scoped_array<sal_uInt8> pBuf(new sal_uInt8[nDataLen]);
+ pOS2MET->Read(pBuf.get(),nDataLen);
if (p->nBitsPerPixel==24) {
sal_uLong i, j, nAlign, nBytesPerLine;
sal_uInt8 nTemp;
@@ -2208,9 +2207,8 @@ void OS2METReader::ReadImageData(sal_uInt16 nDataID, sal_uInt16 nDataLen)
}
}
}
- p->pBMP->Write(pBuf,nDataLen);
+ p->pBMP->Write(pBuf.get(),nDataLen);
p->nMapPos+=nDataLen;
- delete[] pBuf;
break;
}
case 0x0093: // End Image Content
@@ -2505,10 +2503,9 @@ void OS2METReader::ReadField(sal_uInt16 nFieldType, sal_uInt16 nFieldSize)
pOrdFile = new SvMemoryStream;
pOrdFile->SetNumberFormatInt(NUMBERFORMAT_INT_LITTLEENDIAN);
}
- sal_uInt8 * pBuf; pBuf = new sal_uInt8[nFieldSize];
- pOS2MET->Read(pBuf,nFieldSize);
- pOrdFile->Write(pBuf,nFieldSize);
- delete[] pBuf;
+ boost::scoped_array<sal_uInt8> pBuf(new sal_uInt8[nFieldSize]);
+ pOS2MET->Read(pBuf.get(),nFieldSize);
+ pOrdFile->Write(pBuf.get(),nFieldSize);
break;
}
case MapCodFntMagic: