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

Avoid possible resource leaks in case of exceptions

Change-Id: I6f1f6669b222f03ad220f01cae2e09d03550a58b
üst 0a215b9a
......@@ -36,6 +36,7 @@
#include <vcl/salbtype.hxx>
#include <basegfx/polygon/b2dpolygon.hxx>
#include <basegfx/polygon/b2dpolypolygon.hxx>
#include <boost/scoped_array.hpp>
using namespace ::swf;
using namespace ::std;
......@@ -528,21 +529,20 @@ void Writer::Impl_writeText( const Point& rPos, const OUString& rText, const sal
else
{
Size aNormSize;
sal_Int32* pOwnArray;
boost::scoped_array<sal_Int32> pOwnArray;
sal_Int32* pDX;
// get text sizes
if( pDXArray )
{
pOwnArray = NULL;
aNormSize = Size( mpVDev->GetTextWidth( rText ), 0 );
pDX = (sal_Int32*) pDXArray;
}
else
{
pOwnArray = new sal_Int32[ nLen ];
aNormSize = Size( mpVDev->GetTextArray( rText, pOwnArray ), 0 );
pDX = pOwnArray;
pOwnArray.reset(new sal_Int32[ nLen ]);
aNormSize = Size( mpVDev->GetTextArray( rText, pOwnArray.get() ), 0 );
pDX = pOwnArray.get();
}
if( nLen > 1 )
......@@ -720,7 +720,6 @@ void Writer::Impl_writeText( const Point& rPos, const OUString& rText, const sal
}
mpVDev->SetFont( aOldFont );
delete[] pOwnArray;
}
}
......@@ -816,33 +815,33 @@ sal_uInt16 Writer::defineBitmap( const BitmapEx &bmpSource, sal_Int32 nJPEGQuali
getBitmapData( bmpSource, pImageData, pAlphaData, width, height );
sal_uInt32 raw_size = width * height * 4;
uLongf compressed_size = raw_size + (sal_uInt32)(raw_size/100) + 12;
sal_uInt8 *pCompressed = new sal_uInt8[ compressed_size ];
boost::scoped_array<sal_uInt8> pCompressed(new sal_uInt8[ compressed_size ]);
#ifdef DBG_UTIL
if(compress2(pCompressed, &compressed_size, pImageData, raw_size, Z_BEST_COMPRESSION) != Z_OK)
if(compress2(pCompressed.get(), &compressed_size, pImageData, raw_size, Z_BEST_COMPRESSION) != Z_OK)
{
DBG_ASSERT( false, "compress2 failed!" ); ((void)0);
}
#else
compress2(pCompressed, &compressed_size, pImageData, raw_size, Z_BEST_COMPRESSION);
compress2(pCompressed.get(), &compressed_size, pImageData, raw_size, Z_BEST_COMPRESSION);
#endif
// AS: SWF files let you provide an Alpha mask for JPEG images, but we have
// to ZLIB compress the alpha channel separately.
uLong alpha_compressed_size = 0;
sal_uInt8 *pAlphaCompressed = NULL;
boost::scoped_array<sal_uInt8> pAlphaCompressed;
if (bmpSource.IsAlpha() || bmpSource.IsTransparent())
{
alpha_compressed_size = uLongf(width * height + (sal_uInt32)(raw_size/100) + 12);
pAlphaCompressed = new sal_uInt8[ compressed_size ];
pAlphaCompressed.reset(new sal_uInt8[ compressed_size ]);
#ifdef DBG_UTIL
if(compress2(pAlphaCompressed, &alpha_compressed_size, pAlphaData, width * height, Z_BEST_COMPRESSION) != Z_OK)
if(compress2(pAlphaCompressed.get(), &alpha_compressed_size, pAlphaData, width * height, Z_BEST_COMPRESSION) != Z_OK)
{
DBG_ASSERT( false, "compress2 failed!" ); ((void)0);
}
#else
compress2(pAlphaCompressed, &alpha_compressed_size, pAlphaData, width * height, Z_BEST_COMPRESSION);
compress2(pAlphaCompressed.get(), &alpha_compressed_size, pAlphaData, width * height, Z_BEST_COMPRESSION);
#endif
}
......@@ -873,12 +872,10 @@ sal_uInt16 Writer::defineBitmap( const BitmapEx &bmpSource, sal_Int32 nJPEGQuali
// we have to export as TAG_DEFINEBITSJPEG3 in the case that there is alpha
// channel data.
if ( pJpgData && ( nJpgDataLength + alpha_compressed_size < compressed_size) )
Impl_writeJPEG(nBitmapId, pJpgData, nJpgDataLength, pAlphaCompressed, alpha_compressed_size );
Impl_writeJPEG(nBitmapId, pJpgData, nJpgDataLength, pAlphaCompressed.get(), alpha_compressed_size );
else
Impl_writeBmp( nBitmapId, width, height, pCompressed, compressed_size );
Impl_writeBmp( nBitmapId, width, height, pCompressed.get(), compressed_size );
delete[] pCompressed;
delete[] pAlphaCompressed;
delete[] pImageData;
delete[] pAlphaData;
......
......@@ -26,7 +26,7 @@
#include <vcl/fltcall.hxx>
#include <vcl/FilterConfigItem.hxx>
#include "giflzwc.hxx"
#include <boost/scoped_array.hpp>
// - GIFWriter -
......@@ -475,12 +475,12 @@ void GIFWriter::WriteAccess()
GIFLZWCompressor aCompressor;
const long nWidth = m_pAcc->Width();
const long nHeight = m_pAcc->Height();
sal_uInt8* pBuffer = NULL;
boost::scoped_array<sal_uInt8> pBuffer;
const sal_uLong nFormat = m_pAcc->GetScanlineFormat();
sal_Bool bNative = ( BMP_FORMAT_8BIT_PAL == nFormat );
if( !bNative )
pBuffer = new sal_uInt8[ nWidth ];
pBuffer.reset(new sal_uInt8[ nWidth ]);
if( bStatus && ( 8 == m_pAcc->GetBitCount() ) && m_pAcc->HasPalette() )
{
......@@ -522,7 +522,7 @@ void GIFWriter::WriteAccess()
for( long nX = 0L; nX < nWidth; nX++ )
pBuffer[ nX ] = m_pAcc->GetPixelIndex( nY, nX );
aCompressor.Compress( pBuffer, nWidth );
aCompressor.Compress( pBuffer.get(), nWidth );
}
if ( m_rGIF.GetError() )
......@@ -539,8 +539,6 @@ void GIFWriter::WriteAccess()
if ( m_rGIF.GetError() )
bStatus = sal_False;
}
delete[] pBuffer;
}
......
......@@ -36,6 +36,7 @@
#include <svl/solar.hrc>
#include <vcl/gdimetafiletools.hxx>
#include <vcl/dibtools.hxx>
#include <boost/scoped_array.hpp>
// -----------------------------Field Types-------------------------------
......@@ -567,7 +568,7 @@ void METWriter::WriteImageObject(const Bitmap & rBitmap)
sal_uLong nBytesPerLine,i,j,nNumColors,ny,nLines;
sal_uLong nActColMapId;
sal_uInt16 nBitsPerPixel;
sal_uInt8 nbyte, * pBuf;
sal_uInt8 nbyte;
if (bStatus==sal_False)
return;
......@@ -674,7 +675,7 @@ void METWriter::WriteImageObject(const Bitmap & rBitmap)
pMET->WriteUChar( (sal_uInt8)0x08 ).WriteUChar( (sal_uInt8)0x08 );
}
pBuf=new sal_uInt8[nBytesPerLine];
boost::scoped_array<sal_uInt8> pBuf(new sal_uInt8[nBytesPerLine]);
ny=0;
while (ny<nHeight) {
......@@ -691,21 +692,21 @@ void METWriter::WriteImageObject(const Bitmap & rBitmap)
WriteBigEndianShort(0xfe92);
WriteBigEndianShort((sal_uInt16)(nLines*nBytesPerLine));
for (i=0; i<nLines; i++) {
aTemp.Read(pBuf,nBytesPerLine);
aTemp.Read(pBuf.get(),nBytesPerLine);
if (nBitsPerPixel==24) {
for (j=2; j<nBytesPerLine; j+=3) {
nbyte=pBuf[j]; pBuf[j]=pBuf[j-2]; pBuf[j-2]=nbyte;
}
}
pMET->Write(pBuf,nBytesPerLine);
pMET->Write(pBuf.get(),nBytesPerLine);
ny++;
}
if (aTemp.GetError() || pMET->GetError()) bStatus=sal_False;
nActBitmapPercent=(ny+1)*100/nHeight;
MayCallback();
if (bStatus==sal_False) { delete[] pBuf; return; }
if (bStatus==sal_False) return;
}
delete[] pBuf;
pBuf.reset();
// End Image Content:
pMET->WriteUChar( (sal_uInt8)0x93 ).WriteUChar( (sal_uInt8)0x00 );
......@@ -1932,7 +1933,6 @@ void METWriter::WriteOrders( const GDIMetaFile* pMTF )
const MetaStretchTextAction* pA = (const MetaStretchTextAction*) pMA;
VirtualDevice aVDev;
sal_uInt16 i;
sal_Int32* pDXAry;
sal_Int32 nNormSize;
OUString aStr;
Polygon aPolyDummy(1);
......@@ -1957,8 +1957,8 @@ void METWriter::WriteOrders( const GDIMetaFile* pMTF )
METSetChrAngle( nOrientation = aGDIFont.GetOrientation() );
METSetChrSet(FindChrSet(aGDIFont));
aStr = pA->GetText().copy(pA->GetIndex(),pA->GetLen());
pDXAry = new sal_Int32[aStr.getLength()];
nNormSize = aVDev.GetTextArray( aStr, pDXAry );
boost::scoped_array<sal_Int32> pDXAry(new sal_Int32[aStr.getLength()]);
nNormSize = aVDev.GetTextArray( aStr, pDXAry.get() );
for ( i = 0; i < aStr.getLength(); i++ )
{
......@@ -1975,8 +1975,6 @@ void METWriter::WriteOrders( const GDIMetaFile* pMTF )
}
METChrStr( aPt2, OUString( aStr[ i ] ) );
}
delete[] pDXAry;
}
break;
......
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