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

Avoid possible resource leaks by boost::scoped_array

Change-Id: I5a73d3410262c830795c8b132227fcff5f5127e3
üst 5da51525
......@@ -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;
}
......
......@@ -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" ) )
{
......
......@@ -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;
}
}
}
......
......@@ -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;
}
......
......@@ -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
{
......
......@@ -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 );
}
......
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