filter/source/flash/swfwriter1.cxx | 31 ++++++++++-------------- filter/source/graphicfilter/egif/egif.cxx | 10 +++---- filter/source/graphicfilter/eos2met/eos2met.cxx | 20 ++++++--------- 3 files changed, 27 insertions(+), 34 deletions(-)
New commits: commit be8f375039e854775bbb4e03b68d444a9b157e95 Author: Takeshi Abe <t...@fixedpoint.jp> Date: Sat Apr 5 23:56:45 2014 +0900 Avoid possible resource leaks in case of exceptions Change-Id: I6f1f6669b222f03ad220f01cae2e09d03550a58b diff --git a/filter/source/flash/swfwriter1.cxx b/filter/source/flash/swfwriter1.cxx index 4a67720..25b1fb5 100644 --- a/filter/source/flash/swfwriter1.cxx +++ b/filter/source/flash/swfwriter1.cxx @@ -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; diff --git a/filter/source/graphicfilter/egif/egif.cxx b/filter/source/graphicfilter/egif/egif.cxx index 120f7a1..c395974 100644 --- a/filter/source/graphicfilter/egif/egif.cxx +++ b/filter/source/graphicfilter/egif/egif.cxx @@ -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; } diff --git a/filter/source/graphicfilter/eos2met/eos2met.cxx b/filter/source/graphicfilter/eos2met/eos2met.cxx index 44df91f..a481117 100644 --- a/filter/source/graphicfilter/eos2met/eos2met.cxx +++ b/filter/source/graphicfilter/eos2met/eos2met.cxx @@ -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; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits