diff options
author | Takeshi Abe <tabe@fixedpoint.jp> | 2014-03-20 17:41:46 +0900 |
---|---|---|
committer | Takeshi Abe <tabe@fixedpoint.jp> | 2014-03-20 17:43:45 +0900 |
commit | bbdf832d48cb7f89ee9d6e355841a31c672aadd9 (patch) | |
tree | b65a0ba6e8a8fb173eec850babc8b43184f00ef4 | |
parent | 0fe02d03ac7539e9807bc336b23f17029b2a09fb (diff) |
Avoid possible resource leaks by boost::scoped_array
Change-Id: I0da7f9621d2770f49a554fb97591d9cac0bde9be
-rw-r--r-- | vcl/source/gdi/pngwrite.cxx | 8 | ||||
-rw-r--r-- | vcl/source/gdi/salgdilayout.cxx | 37 | ||||
-rw-r--r-- | vcl/source/gdi/salmisc.cxx | 5 | ||||
-rw-r--r-- | vcl/source/gdi/textlayout.cxx | 10 |
4 files changed, 28 insertions, 32 deletions
diff --git a/vcl/source/gdi/pngwrite.cxx b/vcl/source/gdi/pngwrite.cxx index f8a712809701..6ee397751cd9 100644 --- a/vcl/source/gdi/pngwrite.cxx +++ b/vcl/source/gdi/pngwrite.cxx @@ -30,6 +30,7 @@ #include <vcl/svapp.hxx> #include <vcl/alpha.hxx> #include <osl/endian.h> +#include <boost/scoped_array.hpp> #define PNG_DEF_COMPRESSION 6 @@ -308,8 +309,8 @@ bool PNGWriterImpl::ImplWriteHeader() void PNGWriterImpl::ImplWritePalette() { const sal_uLong nCount = mpAccess->GetPaletteEntryCount(); - sal_uInt8* pTempBuf = new sal_uInt8[ nCount*3 ]; - sal_uInt8* pTmp = pTempBuf; + boost::scoped_array<sal_uInt8> pTempBuf(new sal_uInt8[ nCount*3 ]); + sal_uInt8* pTmp = pTempBuf.get(); ImplOpenChunk( PNGCHUNK_PLTE ); @@ -320,9 +321,8 @@ void PNGWriterImpl::ImplWritePalette() *pTmp++ = rColor.GetGreen(); *pTmp++ = rColor.GetBlue(); } - ImplWriteChunk( pTempBuf, nCount*3 ); + ImplWriteChunk( pTempBuf.get(), nCount*3 ); ImplCloseChunk(); - delete[] pTempBuf; } void PNGWriterImpl::ImplWriteTransparent () diff --git a/vcl/source/gdi/salgdilayout.cxx b/vcl/source/gdi/salgdilayout.cxx index ccfae5f6a794..6ef35096e269 100644 --- a/vcl/source/gdi/salgdilayout.cxx +++ b/vcl/source/gdi/salgdilayout.cxx @@ -40,7 +40,7 @@ #include <salprn.hxx> #include <svdata.hxx> #include <outdata.hxx> - +#include <boost/scoped_array.hpp> #include <boost/scoped_ptr.hpp> #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()) ) { - SalPoint* pPtAry2 = new SalPoint[nPoints]; - bool bCopied = mirror( nPoints, pPtAry, pPtAry2, pOutDev ); - drawPolyLine( nPoints, bCopied ? pPtAry2 : pPtAry ); - delete [] pPtAry2; + boost::scoped_array<SalPoint> pPtAry2(new SalPoint[nPoints]); + bool bCopied = mirror( nPoints, pPtAry, pPtAry2.get(), pOutDev ); + drawPolyLine( nPoints, bCopied ? pPtAry2.get() : pPtAry ); } else 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()) ) { - SalPoint* pPtAry2 = new SalPoint[nPoints]; - bool bCopied = mirror( nPoints, pPtAry, pPtAry2, pOutDev ); - drawPolygon( nPoints, bCopied ? pPtAry2 : pPtAry ); - delete [] pPtAry2; + boost::scoped_array<SalPoint> pPtAry2(new SalPoint[nPoints]); + bool bCopied = mirror( nPoints, pPtAry, pPtAry2.get(), pOutDev ); + drawPolygon( nPoints, bCopied ? pPtAry2.get() : pPtAry ); } else drawPolygon( nPoints, pPtAry ); @@ -478,10 +476,9 @@ bool SalGraphics::DrawPolyLineBezier( sal_uInt32 nPoints, const SalPoint* pPtAry bool bResult = false; if( (m_nLayout & SAL_LAYOUT_BIDI_RTL) || (pOutDev && pOutDev->IsRTLEnabled()) ) { - SalPoint* pPtAry2 = new SalPoint[nPoints]; - bool bCopied = mirror( nPoints, pPtAry, pPtAry2, pOutDev ); - bResult = drawPolyLineBezier( nPoints, bCopied ? pPtAry2 : pPtAry, pFlgAry ); - delete [] pPtAry2; + boost::scoped_array<SalPoint> pPtAry2(new SalPoint[nPoints]); + bool bCopied = mirror( nPoints, pPtAry, pPtAry2.get(), pOutDev ); + bResult = drawPolyLineBezier( nPoints, bCopied ? pPtAry2.get() : pPtAry, pFlgAry ); } else bResult = drawPolyLineBezier( nPoints, pPtAry, pFlgAry ); @@ -493,10 +490,9 @@ bool SalGraphics::DrawPolygonBezier( sal_uInt32 nPoints, const SalPoint* pPtAry, bool bResult = false; if( (m_nLayout & SAL_LAYOUT_BIDI_RTL) || (pOutDev && pOutDev->IsRTLEnabled()) ) { - SalPoint* pPtAry2 = new SalPoint[nPoints]; - bool bCopied = mirror( nPoints, pPtAry, pPtAry2, pOutDev ); - bResult = drawPolygonBezier( nPoints, bCopied ? pPtAry2 : pPtAry, pFlgAry ); - delete [] pPtAry2; + boost::scoped_array<SalPoint> pPtAry2(new SalPoint[nPoints]); + bool bCopied = mirror( nPoints, pPtAry, pPtAry2.get(), pOutDev ); + bResult = drawPolygonBezier( nPoints, bCopied ? pPtAry2.get() : pPtAry, pFlgAry ); } else 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()) ) { - SalPoint* pPtAry2 = new SalPoint[nPoints]; - bool bCopied = mirror( nPoints, pPtAry, pPtAry2, pOutDev ); - invert( nPoints, bCopied ? pPtAry2 : pPtAry, nFlags ); - delete [] pPtAry2; + boost::scoped_array<SalPoint> pPtAry2(new SalPoint[nPoints]); + bool bCopied = mirror( nPoints, pPtAry, pPtAry2.get(), pOutDev ); + invert( nPoints, bCopied ? pPtAry2.get() : pPtAry, nFlags ); } else invert( nPoints, pPtAry, nFlags ); diff --git a/vcl/source/gdi/salmisc.cxx b/vcl/source/gdi/salmisc.cxx index 3cbb4f4ae66c..9bb600ff0a5a 100644 --- a/vcl/source/gdi/salmisc.cxx +++ b/vcl/source/gdi/salmisc.cxx @@ -20,6 +20,7 @@ #include <vcl/bmpacc.hxx> #include <vcl/salbtype.hxx> #include <bmpfast.hxx> +#include <boost/scoped_array.hpp> #define IMPL_CASE_GET_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& rDstMask = rDstBuffer.maColorMask; 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 ); for( long nR = 0; nR < 16; nR++ ) @@ -246,8 +247,6 @@ static void ImplTCToPAL( const BitmapBuffer& rSrcBuffer, BitmapBuffer& rDstBuffe DOUBLE_SCANLINES(); } - - delete[] pColToPalMap; } BitmapBuffer* StretchAndConvert( diff --git a/vcl/source/gdi/textlayout.cxx b/vcl/source/gdi/textlayout.cxx index 7d336b511390..05b44b2dd939 100644 --- a/vcl/source/gdi/textlayout.cxx +++ b/vcl/source/gdi/textlayout.cxx @@ -32,6 +32,8 @@ #include <rtl/strbuf.hxx> #endif +#include <boost/scoped_array.hpp> + namespace vcl { @@ -222,10 +224,10 @@ namespace vcl return; } - sal_Int32* pCharWidths = new sal_Int32[ _nLength ]; - long nTextWidth = GetTextArray( _rText, pCharWidths, _nStartIndex, _nLength ); - m_rTargetDevice.DrawTextArray( _rStartPoint, _rText, pCharWidths, _nStartIndex, _nLength ); - delete[] pCharWidths; + boost::scoped_array<sal_Int32> pCharWidths(new sal_Int32[ _nLength ]); + long nTextWidth = GetTextArray( _rText, pCharWidths.get(), _nStartIndex, _nLength ); + m_rTargetDevice.DrawTextArray( _rStartPoint, _rText, pCharWidths.get(), _nStartIndex, _nLength ); + pCharWidths.reset(); m_aCompleteTextRect.Union( Rectangle( _rStartPoint, Size( nTextWidth, m_rTargetDevice.GetTextHeight() ) ) ); } |