[Libreoffice-commits] core.git: vcl/source

Takeshi Abe tabe at fixedpoint.jp
Thu Mar 20 01:44:18 PDT 2014


 vcl/source/gdi/pngwrite.cxx     |    8 ++++----
 vcl/source/gdi/salgdilayout.cxx |   37 ++++++++++++++++---------------------
 vcl/source/gdi/salmisc.cxx      |    5 ++---
 vcl/source/gdi/textlayout.cxx   |   10 ++++++----
 4 files changed, 28 insertions(+), 32 deletions(-)

New commits:
commit bbdf832d48cb7f89ee9d6e355841a31c672aadd9
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date:   Thu Mar 20 17:41:46 2014 +0900

    Avoid possible resource leaks by boost::scoped_array
    
    Change-Id: I0da7f9621d2770f49a554fb97591d9cac0bde9be

diff --git a/vcl/source/gdi/pngwrite.cxx b/vcl/source/gdi/pngwrite.cxx
index f8a7128..6ee3977 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 ccfae5f..6ef3509 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 3cbb4f4..9bb600f 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 7d336b5..05b44b2 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() ) ) );
     }


More information about the Libreoffice-commits mailing list