Avoid possible resource leaks by boost::scoped_array

Change-Id: I0da7f9621d2770f49a554fb97591d9cac0bde9be
This commit is contained in:
Takeshi Abe
2014-03-20 17:41:46 +09:00
parent 0fe02d03ac
commit bbdf832d48
4 changed files with 28 additions and 32 deletions

View File

@@ -30,6 +30,7 @@
#include <vcl/svapp.hxx> #include <vcl/svapp.hxx>
#include <vcl/alpha.hxx> #include <vcl/alpha.hxx>
#include <osl/endian.h> #include <osl/endian.h>
#include <boost/scoped_array.hpp>
#define PNG_DEF_COMPRESSION 6 #define PNG_DEF_COMPRESSION 6
@@ -308,8 +309,8 @@ bool PNGWriterImpl::ImplWriteHeader()
void PNGWriterImpl::ImplWritePalette() void PNGWriterImpl::ImplWritePalette()
{ {
const sal_uLong nCount = mpAccess->GetPaletteEntryCount(); const sal_uLong nCount = mpAccess->GetPaletteEntryCount();
sal_uInt8* pTempBuf = new sal_uInt8[ nCount*3 ]; boost::scoped_array<sal_uInt8> pTempBuf(new sal_uInt8[ nCount*3 ]);
sal_uInt8* pTmp = pTempBuf; sal_uInt8* pTmp = pTempBuf.get();
ImplOpenChunk( PNGCHUNK_PLTE ); ImplOpenChunk( PNGCHUNK_PLTE );
@@ -320,9 +321,8 @@ void PNGWriterImpl::ImplWritePalette()
*pTmp++ = rColor.GetGreen(); *pTmp++ = rColor.GetGreen();
*pTmp++ = rColor.GetBlue(); *pTmp++ = rColor.GetBlue();
} }
ImplWriteChunk( pTempBuf, nCount*3 ); ImplWriteChunk( pTempBuf.get(), nCount*3 );
ImplCloseChunk(); ImplCloseChunk();
delete[] pTempBuf;
} }
void PNGWriterImpl::ImplWriteTransparent () void PNGWriterImpl::ImplWriteTransparent ()

View File

@@ -40,7 +40,7 @@
#include <salprn.hxx> #include <salprn.hxx>
#include <svdata.hxx> #include <svdata.hxx>
#include <outdata.hxx> #include <outdata.hxx>
#include <boost/scoped_array.hpp>
#include <boost/scoped_ptr.hpp> #include <boost/scoped_ptr.hpp>
#include "basegfx/polygon/b2dpolygon.hxx" #include "basegfx/polygon/b2dpolygon.hxx"
@@ -414,10 +414,9 @@ void SalGraphics::DrawPolyLine( sal_uInt32 nPoints, const SalPoint* pPtAry, cons
{ {
if( (m_nLayout & SAL_LAYOUT_BIDI_RTL) || (pOutDev && pOutDev->IsRTLEnabled()) ) if( (m_nLayout & SAL_LAYOUT_BIDI_RTL) || (pOutDev && pOutDev->IsRTLEnabled()) )
{ {
SalPoint* pPtAry2 = new SalPoint[nPoints]; boost::scoped_array<SalPoint> pPtAry2(new SalPoint[nPoints]);
bool bCopied = mirror( nPoints, pPtAry, pPtAry2, pOutDev ); bool bCopied = mirror( nPoints, pPtAry, pPtAry2.get(), pOutDev );
drawPolyLine( nPoints, bCopied ? pPtAry2 : pPtAry ); drawPolyLine( nPoints, bCopied ? pPtAry2.get() : pPtAry );
delete [] pPtAry2;
} }
else else
drawPolyLine( nPoints, pPtAry ); drawPolyLine( nPoints, pPtAry );
@@ -427,10 +426,9 @@ void SalGraphics::DrawPolygon( sal_uInt32 nPoints, const SalPoint* pPtAry, const
{ {
if( (m_nLayout & SAL_LAYOUT_BIDI_RTL) || (pOutDev && pOutDev->IsRTLEnabled()) ) if( (m_nLayout & SAL_LAYOUT_BIDI_RTL) || (pOutDev && pOutDev->IsRTLEnabled()) )
{ {
SalPoint* pPtAry2 = new SalPoint[nPoints]; boost::scoped_array<SalPoint> pPtAry2(new SalPoint[nPoints]);
bool bCopied = mirror( nPoints, pPtAry, pPtAry2, pOutDev ); bool bCopied = mirror( nPoints, pPtAry, pPtAry2.get(), pOutDev );
drawPolygon( nPoints, bCopied ? pPtAry2 : pPtAry ); drawPolygon( nPoints, bCopied ? pPtAry2.get() : pPtAry );
delete [] pPtAry2;
} }
else else
drawPolygon( nPoints, pPtAry ); drawPolygon( nPoints, pPtAry );
@@ -478,10 +476,9 @@ bool SalGraphics::DrawPolyLineBezier( sal_uInt32 nPoints, const SalPoint* pPtAry
bool bResult = false; bool bResult = false;
if( (m_nLayout & SAL_LAYOUT_BIDI_RTL) || (pOutDev && pOutDev->IsRTLEnabled()) ) if( (m_nLayout & SAL_LAYOUT_BIDI_RTL) || (pOutDev && pOutDev->IsRTLEnabled()) )
{ {
SalPoint* pPtAry2 = new SalPoint[nPoints]; boost::scoped_array<SalPoint> pPtAry2(new SalPoint[nPoints]);
bool bCopied = mirror( nPoints, pPtAry, pPtAry2, pOutDev ); bool bCopied = mirror( nPoints, pPtAry, pPtAry2.get(), pOutDev );
bResult = drawPolyLineBezier( nPoints, bCopied ? pPtAry2 : pPtAry, pFlgAry ); bResult = drawPolyLineBezier( nPoints, bCopied ? pPtAry2.get() : pPtAry, pFlgAry );
delete [] pPtAry2;
} }
else else
bResult = drawPolyLineBezier( nPoints, pPtAry, pFlgAry ); bResult = drawPolyLineBezier( nPoints, pPtAry, pFlgAry );
@@ -493,10 +490,9 @@ bool SalGraphics::DrawPolygonBezier( sal_uInt32 nPoints, const SalPoint* pPtAry,
bool bResult = false; bool bResult = false;
if( (m_nLayout & SAL_LAYOUT_BIDI_RTL) || (pOutDev && pOutDev->IsRTLEnabled()) ) if( (m_nLayout & SAL_LAYOUT_BIDI_RTL) || (pOutDev && pOutDev->IsRTLEnabled()) )
{ {
SalPoint* pPtAry2 = new SalPoint[nPoints]; boost::scoped_array<SalPoint> pPtAry2(new SalPoint[nPoints]);
bool bCopied = mirror( nPoints, pPtAry, pPtAry2, pOutDev ); bool bCopied = mirror( nPoints, pPtAry, pPtAry2.get(), pOutDev );
bResult = drawPolygonBezier( nPoints, bCopied ? pPtAry2 : pPtAry, pFlgAry ); bResult = drawPolygonBezier( nPoints, bCopied ? pPtAry2.get() : pPtAry, pFlgAry );
delete [] pPtAry2;
} }
else else
bResult = drawPolygonBezier( nPoints, pPtAry, pFlgAry ); bResult = drawPolygonBezier( nPoints, pPtAry, pFlgAry );
@@ -644,10 +640,9 @@ void SalGraphics::Invert( sal_uInt32 nPoints, const SalPoint* pPtAry, SalInvert
{ {
if( (m_nLayout & SAL_LAYOUT_BIDI_RTL) || (pOutDev && pOutDev->IsRTLEnabled()) ) if( (m_nLayout & SAL_LAYOUT_BIDI_RTL) || (pOutDev && pOutDev->IsRTLEnabled()) )
{ {
SalPoint* pPtAry2 = new SalPoint[nPoints]; boost::scoped_array<SalPoint> pPtAry2(new SalPoint[nPoints]);
bool bCopied = mirror( nPoints, pPtAry, pPtAry2, pOutDev ); bool bCopied = mirror( nPoints, pPtAry, pPtAry2.get(), pOutDev );
invert( nPoints, bCopied ? pPtAry2 : pPtAry, nFlags ); invert( nPoints, bCopied ? pPtAry2.get() : pPtAry, nFlags );
delete [] pPtAry2;
} }
else else
invert( nPoints, pPtAry, nFlags ); invert( nPoints, pPtAry, nFlags );

View File

@@ -20,6 +20,7 @@
#include <vcl/bmpacc.hxx> #include <vcl/bmpacc.hxx>
#include <vcl/salbtype.hxx> #include <vcl/salbtype.hxx>
#include <bmpfast.hxx> #include <bmpfast.hxx>
#include <boost/scoped_array.hpp>
#define IMPL_CASE_GET_FORMAT( Format ) \ #define IMPL_CASE_GET_FORMAT( Format ) \
case( BMP_FORMAT##Format ): \ case( BMP_FORMAT##Format ): \
@@ -217,7 +218,7 @@ static void ImplTCToPAL( const BitmapBuffer& rSrcBuffer, BitmapBuffer& rDstBuffe
const ColorMask& rSrcMask = rSrcBuffer.maColorMask; const ColorMask& rSrcMask = rSrcBuffer.maColorMask;
const ColorMask& rDstMask = rDstBuffer.maColorMask; const ColorMask& rDstMask = rDstBuffer.maColorMask;
BitmapPalette aColMap( rSrcBuffer.maPalette.GetEntryCount() ); BitmapPalette aColMap( rSrcBuffer.maPalette.GetEntryCount() );
sal_uInt8* pColToPalMap = new sal_uInt8[ TC_TO_PAL_COLORS ]; boost::scoped_array<sal_uInt8> pColToPalMap(new sal_uInt8[ TC_TO_PAL_COLORS ]);
BitmapColor aIndex( 0 ); BitmapColor aIndex( 0 );
for( long nR = 0; nR < 16; nR++ ) for( long nR = 0; nR < 16; nR++ )
@@ -246,8 +247,6 @@ static void ImplTCToPAL( const BitmapBuffer& rSrcBuffer, BitmapBuffer& rDstBuffe
DOUBLE_SCANLINES(); DOUBLE_SCANLINES();
} }
delete[] pColToPalMap;
} }
BitmapBuffer* StretchAndConvert( BitmapBuffer* StretchAndConvert(

View File

@@ -32,6 +32,8 @@
#include <rtl/strbuf.hxx> #include <rtl/strbuf.hxx>
#endif #endif
#include <boost/scoped_array.hpp>
namespace vcl namespace vcl
{ {
@@ -222,10 +224,10 @@ namespace vcl
return; return;
} }
sal_Int32* pCharWidths = new sal_Int32[ _nLength ]; boost::scoped_array<sal_Int32> pCharWidths(new sal_Int32[ _nLength ]);
long nTextWidth = GetTextArray( _rText, pCharWidths, _nStartIndex, _nLength ); long nTextWidth = GetTextArray( _rText, pCharWidths.get(), _nStartIndex, _nLength );
m_rTargetDevice.DrawTextArray( _rStartPoint, _rText, pCharWidths, _nStartIndex, _nLength ); m_rTargetDevice.DrawTextArray( _rStartPoint, _rText, pCharWidths.get(), _nStartIndex, _nLength );
delete[] pCharWidths; pCharWidths.reset();
m_aCompleteTextRect.Union( Rectangle( _rStartPoint, Size( nTextWidth, m_rTargetDevice.GetTextHeight() ) ) ); m_aCompleteTextRect.Union( Rectangle( _rStartPoint, Size( nTextWidth, m_rTargetDevice.GetTextHeight() ) ) );
} }