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 @@
#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;
......
......@@ -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 );
}
......
......@@ -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;
......
......@@ -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() ) ) );
}
......
......@@ -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:
......
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