vcl/source/filter/GraphicNativeMetadata.cxx | 8 ++++---- vcl/source/filter/graphicfilter.cxx | 11 +++++------ vcl/source/filter/igif/gifread.cxx | 15 ++++++--------- vcl/source/filter/jpeg/Exif.cxx | 12 +++++------- vcl/source/filter/jpeg/JpegReader.cxx | 5 ++--- vcl/source/filter/jpeg/jpegc.cxx | 16 +++++++--------- 6 files changed, 29 insertions(+), 38 deletions(-)
New commits: commit de660901e1805f33467d425018d6bf5d5326e376 Author: Takeshi Abe <t...@fixedpoint.jp> Date: Wed Mar 12 06:53:08 2014 +0900 Avoid possible resource leaks by boost::scoped_array Change-Id: I5a73d3410262c830795c8b132227fcff5f5127e3 diff --git a/vcl/source/filter/GraphicNativeMetadata.cxx b/vcl/source/filter/GraphicNativeMetadata.cxx index 785f89c..08b698a 100644 --- a/vcl/source/filter/GraphicNativeMetadata.cxx +++ b/vcl/source/filter/GraphicNativeMetadata.cxx @@ -22,6 +22,7 @@ #include <vcl/gfxlink.hxx> #include "jpeg/Exif.hxx" +#include <boost/scoped_array.hpp> GraphicNativeMetadata::GraphicNativeMetadata() : mRotation(0) @@ -41,16 +42,15 @@ bool GraphicNativeMetadata::read(Graphic& rGraphic) if ( aLink.GetType() != GFX_LINK_TYPE_NATIVE_JPG ) return false; sal_uInt32 aDataSize = aLink.GetDataSize(); - sal_uInt8* aBuffer = new sal_uInt8[aDataSize]; + boost::scoped_array<sal_uInt8> aBuffer(new sal_uInt8[aDataSize]); - memcpy(aBuffer, aLink.GetData(), aDataSize); - SvMemoryStream aMemoryStream(aBuffer, aDataSize, STREAM_READ); + memcpy(aBuffer.get(), aLink.GetData(), aDataSize); + SvMemoryStream aMemoryStream(aBuffer.get(), aDataSize, STREAM_READ); Exif aExif; aExif.read(aMemoryStream); mRotation = aExif.getRotation(); - delete[] aBuffer; return true; } diff --git a/vcl/source/filter/graphicfilter.cxx b/vcl/source/filter/graphicfilter.cxx index 7840d61..a033e9b 100644 --- a/vcl/source/filter/graphicfilter.cxx +++ b/vcl/source/filter/graphicfilter.cxx @@ -63,6 +63,7 @@ #include <rtl/instance.hxx> #include <vcl/metaact.hxx> #include <vector> +#include <boost/scoped_array.hpp> #include <boost/scoped_ptr.hpp> #include "FilterConfigCache.hxx" @@ -621,22 +622,20 @@ static bool ImpPeekGraphicFormat( SvStream& rStream, OUString& rFormatExtension, if( !bTest ) { sal_uLong nSize = ( nStreamLen > 2048 ) ? 2048 : nStreamLen; - sal_uInt8* pBuf = new sal_uInt8 [ nSize ]; + boost::scoped_array<sal_uInt8> pBuf(new sal_uInt8 [ nSize ]); rStream.Seek( nStreamPos ); - rStream.Read( pBuf, nSize ); - sal_uInt8* pPtr = ImplSearchEntry( pBuf, (sal_uInt8*)"#define", nSize, 7 ); + rStream.Read( pBuf.get(), nSize ); + sal_uInt8* pPtr = ImplSearchEntry( pBuf.get(), (sal_uInt8*)"#define", nSize, 7 ); if( pPtr ) { - if( ImplSearchEntry( pPtr, (sal_uInt8*)"_width", pBuf + nSize - pPtr, 6 ) ) + if( ImplSearchEntry( pPtr, (sal_uInt8*)"_width", pBuf.get() + nSize - pPtr, 6 ) ) { rFormatExtension = "XBM"; - delete[] pBuf; return true; } } - delete[] pBuf; } else if( rFormatExtension.startsWith( "XBM" ) ) { diff --git a/vcl/source/filter/igif/gifread.cxx b/vcl/source/filter/igif/gifread.cxx index 26ceb86..b3168a0 100644 --- a/vcl/source/filter/igif/gifread.cxx +++ b/vcl/source/filter/igif/gifread.cxx @@ -22,6 +22,7 @@ #include "decode.hxx" #include "gifread.hxx" +#include <boost/scoped_array.hpp> #define NO_PENDING( rStm ) ( ( rStm ).GetError() != ERRCODE_IO_PENDING ) @@ -172,12 +173,12 @@ bool GIFReader::ReadGlobalHeader() void GIFReader::ReadPaletteEntries( BitmapPalette* pPal, sal_uLong nCount ) { const sal_uLong nLen = 3UL * nCount; - sal_uInt8* pBuf = new sal_uInt8[ nLen ]; + boost::scoped_array<sal_uInt8> pBuf(new sal_uInt8[ nLen ]); - rIStm.Read( pBuf, nLen ); + rIStm.Read( pBuf.get(), nLen ); if( NO_PENDING( rIStm ) ) { - sal_uInt8* pTmp = pBuf; + sal_uInt8* pTmp = pBuf.get(); for( sal_uLong i = 0UL; i < nCount; ) { @@ -197,8 +198,6 @@ void GIFReader::ReadPaletteEntries( BitmapPalette* pPal, sal_uLong nCount ) (*pPal)[ 254UL ] = Color( COL_BLACK ); } } - - delete[] pBuf; } bool GIFReader::ReadExtension() @@ -315,10 +314,10 @@ bool GIFReader::ReadExtension() while( cSize && bStatus && !rIStm.IsEof() ) { sal_uInt16 nCount = (sal_uInt16) cSize + 1; - char* pBuffer = new char[ nCount ]; + boost::scoped_array<char> pBuffer(new char[ nCount ]); bRet = false; - rIStm.Read( pBuffer, nCount ); + rIStm.Read( pBuffer.get(), nCount ); if( NO_PENDING( rIStm ) ) { cSize = (sal_uInt8) pBuffer[ cSize ]; @@ -326,8 +325,6 @@ bool GIFReader::ReadExtension() } else cSize = 0; - - delete[] pBuffer; } } } diff --git a/vcl/source/filter/jpeg/Exif.cxx b/vcl/source/filter/jpeg/Exif.cxx index ea4d1314..e7a3287 100644 --- a/vcl/source/filter/jpeg/Exif.cxx +++ b/vcl/source/filter/jpeg/Exif.cxx @@ -18,6 +18,7 @@ */ #include "Exif.hxx" +#include <boost/scoped_array.hpp> Exif::Exif() : maOrientation(TOP_LEFT), @@ -214,10 +215,10 @@ bool Exif::processExif(SvStream& rStream, sal_uInt16 aSectionLength, bool bSetVa sal_uInt16 aLength = aSectionLength - 6; // Length = Section - Header - sal_uInt8* aExifData = new sal_uInt8[aLength]; + boost::scoped_array<sal_uInt8> aExifData(new sal_uInt8[aLength]); sal_uInt32 aExifDataBeginPosition = rStream.Tell(); - rStream.Read(aExifData, aLength); + rStream.Read(aExifData.get(), aLength); // Exif detected mbExifPresent = true; @@ -229,7 +230,6 @@ bool Exif::processExif(SvStream& rStream, sal_uInt16 aSectionLength, bool bSetVa if (!bIntel && !bMotorola) { - delete[] aExifData; return false; } @@ -251,7 +251,6 @@ bool Exif::processExif(SvStream& rStream, sal_uInt16 aSectionLength, bool bSetVa if (aTiffHeader->tagAlign != 0x002A) // TIFF tag { - delete[] aExifData; return false; } @@ -263,15 +262,14 @@ bool Exif::processExif(SvStream& rStream, sal_uInt16 aSectionLength, bool bSetVa aNumberOfTags = ((aExifData[aOffset] << 8) | aExifData[aOffset+1]); } - processIFD(aExifData, aLength, aOffset+2, aNumberOfTags, bSetValue, bSwap); + processIFD(aExifData.get(), aLength, aOffset+2, aNumberOfTags, bSetValue, bSwap); if (bSetValue) { rStream.Seek(aExifDataBeginPosition); - rStream.Write(aExifData, aLength); + rStream.Write(aExifData.get(), aLength); } - delete[] aExifData; return true; } diff --git a/vcl/source/filter/jpeg/JpegReader.cxx b/vcl/source/filter/jpeg/JpegReader.cxx index 2d31249..3159503 100644 --- a/vcl/source/filter/jpeg/JpegReader.cxx +++ b/vcl/source/filter/jpeg/JpegReader.cxx @@ -28,6 +28,7 @@ #include <vcl/bmpacc.hxx> #include <vcl/FilterConfigItem.hxx> #include <vcl/graphicfilter.hxx> +#include <boost/scoped_array.hpp> #define JPEG_MIN_READ 512 #define BUFFER_SIZE 4096 @@ -313,7 +314,7 @@ void JPEGReader::FillBitmap() if( mpAcc->GetBitCount() == 8 ) { - BitmapColor* pCols = new BitmapColor[ 256 ]; + boost::scoped_array<BitmapColor> pCols(new BitmapColor[ 256 ]); for( sal_uInt16 n = 0; n < 256; n++ ) { @@ -332,8 +333,6 @@ void JPEGReader::FillBitmap() mpAcc->SetPixel( nY, nX, pCols[ *pTmp++ ] ); } } - - delete[] pCols; } else { diff --git a/vcl/source/filter/jpeg/jpegc.cxx b/vcl/source/filter/jpeg/jpegc.cxx index 6cbb589..198aeaf 100644 --- a/vcl/source/filter/jpeg/jpegc.cxx +++ b/vcl/source/filter/jpeg/jpegc.cxx @@ -35,6 +35,7 @@ extern "C" { #include "jpeg.h" #include <JpegReader.hxx> #include <JpegWriter.hxx> +#include <boost/scoped_array.hpp> struct ErrorManagerStruct { @@ -67,7 +68,7 @@ void ReadJPEG( JPEGReader* pJPEGReader, void* pInputStream, long* pLines, long nHeight; long nAlignedWidth; JSAMPLE* aRangeLimit; - unsigned char * pScanLineBuffer = NULL; + boost::scoped_array<unsigned char> pScanLineBuffer; long nScanLineBufferComponents = 0; if ( setjmp( jerr.setjmp_buffer ) ) @@ -152,7 +153,7 @@ void ReadJPEG( JPEGReader* pJPEGReader, void* pInputStream, long* pLines, if ( cinfo.out_color_space == JCS_CMYK ) { nScanLineBufferComponents = cinfo.output_width * 4; - pScanLineBuffer = new unsigned char[nScanLineBufferComponents]; + pScanLineBuffer.reset(new unsigned char[nScanLineBufferComponents]); } if( pDIB ) @@ -169,11 +170,12 @@ void ReadJPEG( JPEGReader* pJPEGReader, void* pInputStream, long* pLines, for ( *pLines = 0; *pLines < nHeight; (*pLines)++ ) { - if (pScanLineBuffer != NULL) + if (pScanLineBuffer) { // in other words cinfo.out_color_space == JCS_CMYK int i; int j; - jpeg_read_scanlines( &cinfo, (JSAMPARRAY) &pScanLineBuffer, 1 ); + unsigned char *pSLB = pScanLineBuffer.get(); + jpeg_read_scanlines( &cinfo, (JSAMPARRAY) &pSLB, 1 ); // convert CMYK to RGB for( i=0, j=0; i < nScanLineBufferComponents; i+=4, j+=3 ) { @@ -208,11 +210,7 @@ void ReadJPEG( JPEGReader* pJPEGReader, void* pInputStream, long* pLines, jpeg_abort_decompress( &cinfo ); } - if (pScanLineBuffer != NULL) - { - delete[] pScanLineBuffer; - pScanLineBuffer = NULL; - } + pScanLineBuffer.reset(); jpeg_destroy_decompress( &cinfo ); } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits