Kaydet (Commit) 099dd432 authored tarafından Takeshi Abe's avatar Takeshi Abe

Avoid possible memory leaks in case of exceptions

Change-Id: If541e39e34490adccc8baab43ea9516c3dc6cc1a
üst 4973486e
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include <basegfx/polygon/b2dpolygon.hxx> #include <basegfx/polygon/b2dpolygon.hxx>
#include <basegfx/polygon/b2dpolypolygon.hxx> #include <basegfx/polygon/b2dpolypolygon.hxx>
#include <boost/scoped_array.hpp>
// PictWriter // PictWriter
struct PictWriterAttrStackMember { struct PictWriterAttrStackMember {
...@@ -871,7 +872,7 @@ void PictWriter::WriteOpcode_BitsRect(const Point & rPoint, const Size & rSize, ...@@ -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 nWidth, nHeight, nDstRowBytes, nx, nc, ny, nCount, nColTabSize, i;
sal_uLong nDstRowPos, nSrcRowBytes, nEqu3, nPos, nDstMapPos; sal_uLong nDstRowPos, nSrcRowBytes, nEqu3, nPos, nDstMapPos;
sal_uInt16 nBitsPerPixel, nPackType; sal_uInt16 nBitsPerPixel, nPackType;
sal_uInt8 *pComp[4], *pPix, *pTemp; sal_uInt8 *pComp[4], *pTemp;
sal_uInt8 nEquData = 0; sal_uInt8 nEquData = 0;
sal_uInt8 nFlagCounterByte, nRed, nGreen, nBlue; sal_uInt8 nFlagCounterByte, nRed, nGreen, nBlue;
...@@ -1141,7 +1142,7 @@ void PictWriter::WriteOpcode_BitsRect(const Point & rPoint, const Size & rSize, ...@@ -1141,7 +1142,7 @@ void PictWriter::WriteOpcode_BitsRect(const Point & rPoint, const Size & rSize,
pPict->WriteUInt16( (sal_uInt16)0 ); // (?) pPict->WriteUInt16( (sal_uInt16)0 ); // (?)
// allocate memory for a row: // 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: // remember position of the map-data in the target:
nDstMapPos=pPict->Tell(); nDstMapPos=pPict->Tell();
...@@ -1153,13 +1154,13 @@ void PictWriter::WriteOpcode_BitsRect(const Point & rPoint, const Size & rSize, ...@@ -1153,13 +1154,13 @@ void PictWriter::WriteOpcode_BitsRect(const Point & rPoint, const Size & rSize,
switch ( nBitsPerPixel ) switch ( nBitsPerPixel )
{ {
case 1 : case 1 :
for ( pTemp = pPix, i = 0; i < nSrcRowBytes; i++ ) for ( pTemp = pPix.get(), i = 0; i < nSrcRowBytes; i++ )
*pTemp++ = (sal_uInt8)0; *pTemp++ = (sal_uInt8)0;
for ( i = 0; i < nWidth; i++ ) for ( i = 0; i < nWidth; i++ )
pPix[ ( i >> 3 ) ] |= (pAcc->GetPixelIndex( ny, i ) & 1) << ((i & 7) ^ 7); pPix[ ( i >> 3 ) ] |= (pAcc->GetPixelIndex( ny, i ) & 1) << ((i & 7) ^ 7);
break; break;
case 4 : case 4 :
for ( pTemp = pPix, i = 0; i < nSrcRowBytes; i++ ) for ( pTemp = pPix.get(), i = 0; i < nSrcRowBytes; i++ )
*pTemp++ = (sal_uInt8)0; *pTemp++ = (sal_uInt8)0;
for ( i = 0; i < nWidth; i++ ) for ( i = 0; i < nWidth; i++ )
pPix[ ( i >> 1 ) ] |= (pAcc->GetPixelIndex( ny, i ) & 15) << ((i & 1) << 2); 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, ...@@ -1172,7 +1173,7 @@ void PictWriter::WriteOpcode_BitsRect(const Point & rPoint, const Size & rSize,
if ( nPackType == 1 ) if ( nPackType == 1 )
{ // don't pack { // don't pack
pPict->Write( pPix, nDstRowBytes ); pPict->Write( pPix.get(), nDstRowBytes );
} }
else else
{ // Ppacking (nPackType==0) { // Ppacking (nPackType==0)
...@@ -1256,8 +1257,6 @@ void PictWriter::WriteOpcode_BitsRect(const Point & rPoint, const Size & rSize, ...@@ -1256,8 +1257,6 @@ void PictWriter::WriteOpcode_BitsRect(const Point & rPoint, const Size & rSize,
if ( pPict->GetError() ) if ( pPict->GetError() )
bStatus = sal_False; bStatus = sal_False;
} }
// cleaning up:
delete[] pPix;
} }
// Map-Data has to be an even number of bytes: // Map-Data has to be an even number of bytes:
...@@ -1744,8 +1743,8 @@ void PictWriter::WriteOpcodes( const GDIMetaFile & rMTF ) ...@@ -1744,8 +1743,8 @@ void PictWriter::WriteOpcodes( const GDIMetaFile & rMTF )
Point aPt( pA->GetPoint() ); Point aPt( pA->GetPoint() );
OUString aStr = pA->GetText().copy( pA->GetIndex(),pA->GetLen() ); OUString aStr = pA->GetText().copy( pA->GetIndex(),pA->GetLen() );
VirtualDevice aVirDev; VirtualDevice aVirDev;
sal_Int32* pDXAry = new sal_Int32[ aStr.getLength() ]; boost::scoped_array<sal_Int32> pDXAry(new sal_Int32[ aStr.getLength() ]);
sal_Int32 nNormSize( aVirDev.GetTextArray( aStr,pDXAry ) ); sal_Int32 nNormSize( aVirDev.GetTextArray( aStr,pDXAry.get() ) );
sal_uInt16 i; sal_uInt16 i;
if (aSrcFont.GetAlign()!=ALIGN_BASELINE) if (aSrcFont.GetAlign()!=ALIGN_BASELINE)
...@@ -1760,8 +1759,7 @@ void PictWriter::WriteOpcodes( const GDIMetaFile & rMTF ) ...@@ -1760,8 +1759,7 @@ void PictWriter::WriteOpcodes( const GDIMetaFile & rMTF )
pDXAry[ i ] = pDXAry[ i ] * ( (long)pA->GetWidth() ) / nNormSize; pDXAry[ i ] = pDXAry[ i ] * ( (long)pA->GetWidth() ) / nNormSize;
SetAttrForText(); SetAttrForText();
WriteTextArray( aPt, aStr, pDXAry ); WriteTextArray( aPt, aStr, pDXAry.get() );
delete[] pDXAry;
} }
break; break;
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "bundles.hxx" #include "bundles.hxx"
#include <tools/stream.hxx> #include <tools/stream.hxx>
#include <boost/scoped_array.hpp>
Bundle& Bundle::operator=( Bundle& rSource ) Bundle& Bundle::operator=( Bundle& rSource )
{ {
...@@ -191,13 +192,13 @@ void CGMFList::InsertName( sal_uInt8* pSource, sal_uInt32 nSize ) ...@@ -191,13 +192,13 @@ void CGMFList::InsertName( sal_uInt8* pSource, sal_uInt32 nSize )
pFontEntry = aFontEntryList[ nFontNameCount ]; pFontEntry = aFontEntryList[ nFontNameCount ];
} }
nFontNameCount++; nFontNameCount++;
sal_Int8* pBuf = new sal_Int8[ nSize ]; boost::scoped_array<sal_Int8> pBuf(new sal_Int8[ nSize ]);
memcpy( pBuf, pSource, nSize ); memcpy( pBuf.get(), pSource, nSize );
sal_Int8* pFound = ImplSearchEntry( pBuf, (sal_Int8*)"ITALIC", nSize, 6 ); sal_Int8* pFound = ImplSearchEntry( pBuf.get(), (sal_Int8*)"ITALIC", nSize, 6 );
if ( pFound ) if ( pFound )
{ {
pFontEntry->nFontType |= 1; pFontEntry->nFontType |= 1;
sal_uInt32 nPrev = ( pFound - pBuf ); sal_uInt32 nPrev = ( pFound - pBuf.get() );
sal_uInt32 nToCopyOfs = 6; sal_uInt32 nToCopyOfs = 6;
if ( nPrev && ( pFound[ -1 ] == '-' || pFound[ -1 ] == ' ' ) ) if ( nPrev && ( pFound[ -1 ] == '-' || pFound[ -1 ] == ' ' ) )
{ {
...@@ -212,12 +213,12 @@ void CGMFList::InsertName( sal_uInt8* pSource, sal_uInt32 nSize ) ...@@ -212,12 +213,12 @@ void CGMFList::InsertName( sal_uInt8* pSource, sal_uInt32 nSize )
} }
nSize -= nToCopyOfs; nSize -= nToCopyOfs;
} }
pFound = ImplSearchEntry( pBuf, (sal_Int8*)"BOLD", nSize, 4 ); pFound = ImplSearchEntry( pBuf.get(), (sal_Int8*)"BOLD", nSize, 4 );
if ( pFound ) if ( pFound )
{ {
pFontEntry->nFontType |= 2; pFontEntry->nFontType |= 2;
sal_uInt32 nPrev = ( pFound - pBuf ); sal_uInt32 nPrev = ( pFound - pBuf.get() );
sal_uInt32 nToCopyOfs = 4; sal_uInt32 nToCopyOfs = 4;
if ( nPrev && ( pFound[ -1 ] == '-' || pFound[ -1 ] == ' ' ) ) if ( nPrev && ( pFound[ -1 ] == '-' || pFound[ -1 ] == ' ' ) )
{ {
...@@ -234,8 +235,7 @@ void CGMFList::InsertName( sal_uInt8* pSource, sal_uInt32 nSize ) ...@@ -234,8 +235,7 @@ void CGMFList::InsertName( sal_uInt8* pSource, sal_uInt32 nSize )
} }
pFontEntry->pFontName = new sal_Int8[ nSize + 1 ]; pFontEntry->pFontName = new sal_Int8[ nSize + 1 ];
pFontEntry->pFontName[ nSize ] = 0; pFontEntry->pFontName[ nSize ] = 0;
memcpy( pFontEntry->pFontName, pBuf, nSize ); memcpy( pFontEntry->pFontName, pBuf.get(), nSize );
delete[] pBuf;
} }
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <chart.hxx> #include <chart.hxx>
#include <outact.hxx> #include <outact.hxx>
#include <math.h> #include <math.h>
#include <boost/scoped_array.hpp>
using namespace ::com::sun::star; using namespace ::com::sun::star;
...@@ -270,7 +271,7 @@ void CGM::ImplDoClass4() ...@@ -270,7 +271,7 @@ void CGM::ImplDoClass4()
mpOutAct->CloseRegion(); mpOutAct->CloseRegion();
sal_uInt16 nPoints = 0; sal_uInt16 nPoints = 0;
Point* pPoints = new Point[ 0x4000 ]; boost::scoped_array<Point> pPoints(new Point[ 0x4000 ]);
PolyPolygon aPolyPolygon; PolyPolygon aPolyPolygon;
FloatPoint aFloatPoint; FloatPoint aFloatPoint;
...@@ -291,7 +292,7 @@ void CGM::ImplDoClass4() ...@@ -291,7 +292,7 @@ void CGM::ImplDoClass4()
nPoints = 0; nPoints = 0;
} }
} }
delete[] pPoints; pPoints.reset();
mpOutAct->DrawPolyPolygon( aPolyPolygon ); mpOutAct->DrawPolyPolygon( aPolyPolygon );
} }
break; break;
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include <unotools/tempfile.hxx> #include <unotools/tempfile.hxx>
#include <osl/process.h> #include <osl/process.h>
#include <osl/file.hxx> #include <osl/file.hxx>
#include <boost/scoped_array.hpp>
class FilterConfigItem; class FilterConfigItem;
...@@ -367,19 +368,17 @@ void CreateMtfReplacementAction( GDIMetaFile& rMtf, SvStream& rStrm, sal_uInt32 ...@@ -367,19 +368,17 @@ void CreateMtfReplacementAction( GDIMetaFile& rMtf, SvStream& rStrm, sal_uInt32
.WriteUInt32( nTPos ).WriteUInt32( nSizeTIFF ); .WriteUInt32( nTPos ).WriteUInt32( nSizeTIFF );
if ( nSizeWMF ) if ( nSizeWMF )
{ {
sal_uInt8* pBuf = new sal_uInt8[ nSizeWMF ]; boost::scoped_array<sal_uInt8> pBuf(new sal_uInt8[ nSizeWMF ]);
rStrm.Seek( nOrigPos + nPosWMF ); rStrm.Seek( nOrigPos + nPosWMF );
rStrm.Read( pBuf, nSizeWMF ); rStrm.Read( pBuf.get(), nSizeWMF );
aReplacement.Write( pBuf, nSizeWMF ); aReplacement.Write( pBuf.get(), nSizeWMF );
delete[] pBuf;
} }
if ( nSizeTIFF ) if ( nSizeTIFF )
{ {
sal_uInt8* pBuf = new sal_uInt8[ nSizeTIFF ]; boost::scoped_array<sal_uInt8> pBuf(new sal_uInt8[ nSizeTIFF ]);
rStrm.Seek( nOrigPos + nPosTIFF ); rStrm.Seek( nOrigPos + nPosTIFF );
rStrm.Read( pBuf, nSizeTIFF ); rStrm.Read( pBuf.get(), nSizeTIFF );
aReplacement.Write( pBuf, nSizeTIFF ); aReplacement.Write( pBuf.get(), nSizeTIFF );
delete[] pBuf;
} }
rMtf.AddAction( (MetaAction*)( new MetaCommentAction( aComment, 0, (const sal_uInt8*)aReplacement.GetData(), aReplacement.Tell() ) ) ); rMtf.AddAction( (MetaAction*)( new MetaCommentAction( aComment, 0, (const sal_uInt8*)aReplacement.GetData(), aReplacement.Tell() ) ) );
} }
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <vcl/lineinfo.hxx> #include <vcl/lineinfo.hxx>
#include <math.h> #include <math.h>
#include <boost/scoped_array.hpp>
class FilterConfigItem; class FilterConfigItem;
...@@ -944,7 +945,6 @@ void OS2METReader::ReadChrStr(sal_Bool bGivenPos, sal_Bool bMove, sal_Bool bExtr ...@@ -944,7 +945,6 @@ void OS2METReader::ReadChrStr(sal_Bool bGivenPos, sal_Bool bMove, sal_Bool bExtr
{ {
Point aP0; Point aP0;
sal_uInt16 i, nLen; sal_uInt16 i, nLen;
char * pChr;
OSFont * pF; OSFont * pF;
Font aFont; Font aFont;
Size aSize; Size aSize;
...@@ -978,11 +978,11 @@ void OS2METReader::ReadChrStr(sal_Bool bGivenPos, sal_Bool bMove, sal_Bool bExtr ...@@ -978,11 +978,11 @@ void OS2METReader::ReadChrStr(sal_Bool bGivenPos, sal_Bool bMove, sal_Bool bExtr
else else
nLen = nOrderLen-4; nLen = nOrderLen-4;
} }
pChr = new char[nLen+1]; boost::scoped_array<char> pChr(new char[nLen+1]);
for (i=0; i<nLen; i++) for (i=0; i<nLen; i++)
pOS2MET->ReadChar( pChr[i] ); pOS2MET->ReadChar( pChr[i] );
pChr[nLen] = 0; 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); SetRasterOp(aAttr.eChrMix);
if (pVirDev->GetFont()!=aFont) if (pVirDev->GetFont()!=aFont)
pVirDev->SetFont(aFont); pVirDev->SetFont(aFont);
...@@ -1010,7 +1010,6 @@ void OS2METReader::ReadChrStr(sal_Bool bGivenPos, sal_Bool bMove, sal_Bool bExtr ...@@ -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( 0 ), aDummyPoly.GetPoint( 3 ) ) );
aCalcBndRect.Union( Rectangle( aDummyPoly.GetPoint( 1 ), aDummyPoly.GetPoint( 2 ) ) ); aCalcBndRect.Union( Rectangle( aDummyPoly.GetPoint( 1 ), aDummyPoly.GetPoint( 2 ) ) );
} }
delete[] pChr;
} }
void OS2METReader::ReadArc(sal_Bool bGivenPos) void OS2METReader::ReadArc(sal_Bool bGivenPos)
...@@ -2189,8 +2188,8 @@ void OS2METReader::ReadImageData(sal_uInt16 nDataID, sal_uInt16 nDataLen) ...@@ -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 // OK, now the map data is beeing pushed. Unfortunatly OS2 and BMP
// do habe a different RGB ordering when using 24-bit // do habe a different RGB ordering when using 24-bit
sal_uInt8 * pBuf=new sal_uInt8[nDataLen]; boost::scoped_array<sal_uInt8> pBuf(new sal_uInt8[nDataLen]);
pOS2MET->Read(pBuf,nDataLen); pOS2MET->Read(pBuf.get(),nDataLen);
if (p->nBitsPerPixel==24) { if (p->nBitsPerPixel==24) {
sal_uLong i, j, nAlign, nBytesPerLine; sal_uLong i, j, nAlign, nBytesPerLine;
sal_uInt8 nTemp; sal_uInt8 nTemp;
...@@ -2208,9 +2207,8 @@ void OS2METReader::ReadImageData(sal_uInt16 nDataID, sal_uInt16 nDataLen) ...@@ -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; p->nMapPos+=nDataLen;
delete[] pBuf;
break; break;
} }
case 0x0093: // End Image Content case 0x0093: // End Image Content
...@@ -2505,10 +2503,9 @@ void OS2METReader::ReadField(sal_uInt16 nFieldType, sal_uInt16 nFieldSize) ...@@ -2505,10 +2503,9 @@ void OS2METReader::ReadField(sal_uInt16 nFieldType, sal_uInt16 nFieldSize)
pOrdFile = new SvMemoryStream; pOrdFile = new SvMemoryStream;
pOrdFile->SetNumberFormatInt(NUMBERFORMAT_INT_LITTLEENDIAN); pOrdFile->SetNumberFormatInt(NUMBERFORMAT_INT_LITTLEENDIAN);
} }
sal_uInt8 * pBuf; pBuf = new sal_uInt8[nFieldSize]; boost::scoped_array<sal_uInt8> pBuf(new sal_uInt8[nFieldSize]);
pOS2MET->Read(pBuf,nFieldSize); pOS2MET->Read(pBuf.get(),nFieldSize);
pOrdFile->Write(pBuf,nFieldSize); pOrdFile->Write(pBuf.get(),nFieldSize);
delete[] pBuf;
break; break;
} }
case MapCodFntMagic: case MapCodFntMagic:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment