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

Avoid possible resource leaks by boost::scoped_array

Change-Id: If9b4a70895ae22ef40d9d1fa83ecbf9131c836af
üst 3e2cda22
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <impbmp.hxx> #include <impbmp.hxx>
#include <salbmp.hxx> #include <salbmp.hxx>
#include <boost/scoped_array.hpp>
Bitmap::Bitmap() : Bitmap::Bitmap() :
mpImpBmp( NULL ) mpImpBmp( NULL )
...@@ -584,19 +585,18 @@ bool Bitmap::Mirror( sal_uLong nMirrorFlags ) ...@@ -584,19 +585,18 @@ bool Bitmap::Mirror( sal_uLong nMirrorFlags )
if( pAcc ) if( pAcc )
{ {
const long nScanSize = pAcc->GetScanlineSize(); const long nScanSize = pAcc->GetScanlineSize();
sal_uInt8* pBuffer = new sal_uInt8[ nScanSize ]; boost::scoped_array<sal_uInt8> pBuffer(new sal_uInt8[ nScanSize ]);
const long nHeight = pAcc->Height(); const long nHeight = pAcc->Height();
const long nHeight1 = nHeight - 1L; const long nHeight1 = nHeight - 1L;
const long nHeight_2 = nHeight >> 1L; const long nHeight_2 = nHeight >> 1L;
for( long nY = 0L, nOther = nHeight1; nY < nHeight_2; nY++, nOther-- ) for( long nY = 0L, nOther = nHeight1; nY < nHeight_2; nY++, nOther-- )
{ {
memcpy( pBuffer, pAcc->GetScanline( nY ), nScanSize ); memcpy( pBuffer.get(), pAcc->GetScanline( nY ), nScanSize );
memcpy( pAcc->GetScanline( nY ), pAcc->GetScanline( nOther ), nScanSize ); memcpy( pAcc->GetScanline( nY ), pAcc->GetScanline( nOther ), nScanSize );
memcpy( pAcc->GetScanline( nOther ), pBuffer, nScanSize ); memcpy( pAcc->GetScanline( nOther ), pBuffer.get(), nScanSize );
} }
delete[] pBuffer;
ReleaseAccess( pAcc ); ReleaseAccess( pAcc );
bRet = true; bRet = true;
} }
...@@ -726,10 +726,10 @@ bool Bitmap::Rotate( long nAngle10, const Color& rFillColor ) ...@@ -726,10 +726,10 @@ bool Bitmap::Rotate( long nAngle10, const Color& rFillColor )
long nRotY; long nRotY;
long nSinY; long nSinY;
long nCosY; long nCosY;
long* pCosX = new long[ nNewWidth ]; boost::scoped_array<long> pCosX(new long[ nNewWidth ]);
long* pSinX = new long[ nNewWidth ]; boost::scoped_array<long> pSinX(new long[ nNewWidth ]);
long* pCosY = new long[ nNewHeight ]; boost::scoped_array<long> pCosY(new long[ nNewHeight ]);
long* pSinY = new long[ nNewHeight ]; boost::scoped_array<long> pSinY(new long[ nNewHeight ]);
for ( nX = 0; nX < nNewWidth; nX++ ) for ( nX = 0; nX < nNewWidth; nX++ )
{ {
...@@ -764,11 +764,6 @@ bool Bitmap::Rotate( long nAngle10, const Color& rFillColor ) ...@@ -764,11 +764,6 @@ bool Bitmap::Rotate( long nAngle10, const Color& rFillColor )
} }
} }
delete[] pSinX;
delete[] pCosX;
delete[] pSinY;
delete[] pCosY;
aNewBmp.ReleaseAccess( pWriteAcc ); aNewBmp.ReleaseAccess( pWriteAcc );
} }
...@@ -925,7 +920,7 @@ bool Bitmap::CopyPixel( const Rectangle& rRectDst, ...@@ -925,7 +920,7 @@ bool Bitmap::CopyPixel( const Rectangle& rRectDst,
if( pReadAcc->HasPalette() && pWriteAcc->HasPalette() ) if( pReadAcc->HasPalette() && pWriteAcc->HasPalette() )
{ {
const sal_uInt16 nCount = pReadAcc->GetPaletteEntryCount(); const sal_uInt16 nCount = pReadAcc->GetPaletteEntryCount();
sal_uInt8* pMap = new sal_uInt8[ nCount ]; boost::scoped_array<sal_uInt8> pMap(new sal_uInt8[ nCount ]);
// Create index map for the color table, as the bitmap should be copied // Create index map for the color table, as the bitmap should be copied
// retaining it's color information relatively well // retaining it's color information relatively well
...@@ -935,8 +930,6 @@ bool Bitmap::CopyPixel( const Rectangle& rRectDst, ...@@ -935,8 +930,6 @@ bool Bitmap::CopyPixel( const Rectangle& rRectDst,
for( long nSrcY = aRectSrc.Top(); nSrcY < nSrcEndY; nSrcY++, nDstY++ ) for( long nSrcY = aRectSrc.Top(); nSrcY < nSrcEndY; nSrcY++, nDstY++ )
for( long nSrcX = aRectSrc.Left(), nDstX = aRectDst.Left(); nSrcX < nSrcEndX; nSrcX++, nDstX++ ) for( long nSrcX = aRectSrc.Left(), nDstX = aRectDst.Left(); nSrcX < nSrcEndX; nSrcX++, nDstX++ )
pWriteAcc->SetPixelIndex( nDstY, nDstX, pMap[ pReadAcc->GetPixelIndex( nSrcY, nSrcX ) ] ); pWriteAcc->SetPixelIndex( nDstY, nDstX, pMap[ pReadAcc->GetPixelIndex( nSrcY, nSrcX ) ] );
delete[] pMap;
} }
else if( pReadAcc->HasPalette() ) else if( pReadAcc->HasPalette() )
{ {
...@@ -1403,10 +1396,10 @@ bool Bitmap::Replace( const Bitmap& rMask, const Color& rReplaceColor ) ...@@ -1403,10 +1396,10 @@ bool Bitmap::Replace( const Bitmap& rMask, const Color& rReplaceColor )
} }
else else
{ {
bool* pFlags = new bool[ nMaxColors ]; boost::scoped_array<bool> pFlags(new bool[ nMaxColors ]);
// Set all entries to false // Set all entries to false
std::fill( pFlags, pFlags+nMaxColors, false ); std::fill( pFlags.get(), pFlags.get()+nMaxColors, false );
for( long nY = 0L; nY < nHeight; nY++ ) for( long nY = 0L; nY < nHeight; nY++ )
for( long nX = 0L; nX < nWidth; nX++ ) for( long nX = 0L; nX < nWidth; nX++ )
...@@ -1421,8 +1414,6 @@ bool Bitmap::Replace( const Bitmap& rMask, const Color& rReplaceColor ) ...@@ -1421,8 +1414,6 @@ bool Bitmap::Replace( const Bitmap& rMask, const Color& rReplaceColor )
aReplace = BitmapColor( (sal_uInt8) i ); aReplace = BitmapColor( (sal_uInt8) i );
} }
} }
delete[] pFlags;
} }
} }
} }
...@@ -1561,12 +1552,12 @@ bool Bitmap::Replace( const Color* pSearchColors, const Color* pReplaceColors, ...@@ -1561,12 +1552,12 @@ bool Bitmap::Replace( const Color* pSearchColors, const Color* pReplaceColors,
if( pAcc ) if( pAcc )
{ {
long* pMinR = new long[ nColorCount ]; boost::scoped_array<long> pMinR(new long[ nColorCount ]);
long* pMaxR = new long[ nColorCount ]; boost::scoped_array<long> pMaxR(new long[ nColorCount ]);
long* pMinG = new long[ nColorCount ]; boost::scoped_array<long> pMinG(new long[ nColorCount ]);
long* pMaxG = new long[ nColorCount ]; boost::scoped_array<long> pMaxG(new long[ nColorCount ]);
long* pMinB = new long[ nColorCount ]; boost::scoped_array<long> pMinB(new long[ nColorCount ]);
long* pMaxB = new long[ nColorCount ]; boost::scoped_array<long> pMaxB(new long[ nColorCount ]);
long* pTols; long* pTols;
sal_uLong i; sal_uLong i;
...@@ -1612,7 +1603,7 @@ bool Bitmap::Replace( const Color* pSearchColors, const Color* pReplaceColors, ...@@ -1612,7 +1603,7 @@ bool Bitmap::Replace( const Color* pSearchColors, const Color* pReplaceColors,
else else
{ {
BitmapColor aCol; BitmapColor aCol;
BitmapColor* pReplaces = new BitmapColor[ nColorCount ]; boost::scoped_array<BitmapColor> pReplaces(new BitmapColor[ nColorCount ]);
for( i = 0UL; i < nColorCount; i++ ) for( i = 0UL; i < nColorCount; i++ )
pReplaces[ i ] = pAcc->GetBestMatchingColor( pReplaceColors[ i ] ); pReplaces[ i ] = pAcc->GetBestMatchingColor( pReplaceColors[ i ] );
...@@ -1635,19 +1626,11 @@ bool Bitmap::Replace( const Color* pSearchColors, const Color* pReplaceColors, ...@@ -1635,19 +1626,11 @@ bool Bitmap::Replace( const Color* pSearchColors, const Color* pReplaceColors,
} }
} }
} }
delete[] pReplaces;
} }
if( !_pTols ) if( !_pTols )
delete[] pTols; delete[] pTols;
delete[] pMinR;
delete[] pMaxR;
delete[] pMinG;
delete[] pMaxG;
delete[] pMinB;
delete[] pMaxB;
ReleaseAccess( pAcc ); ReleaseAccess( pAcc );
bRet = true; bRet = true;
} }
......
This diff is collapsed.
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