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

Takeshi Abe tabe at fixedpoint.jp
Mon Mar 10 17:31:20 PDT 2014


 vcl/generic/fontmanager/helper.cxx |   13 ++++--------
 vcl/source/app/dbggui.cxx          |    7 ++----
 vcl/source/control/edit.cxx        |   40 +++++++++++++------------------------
 3 files changed, 23 insertions(+), 37 deletions(-)

New commits:
commit 59b428189d14da78e761c8dbb8bd8ba7de4fa511
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date:   Tue Mar 11 09:24:30 2014 +0900

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

diff --git a/vcl/generic/fontmanager/helper.cxx b/vcl/generic/fontmanager/helper.cxx
index 729d526..a35264f 100644
--- a/vcl/generic/fontmanager/helper.cxx
+++ b/vcl/generic/fontmanager/helper.cxx
@@ -31,6 +31,7 @@
 #include <tools/urlobj.hxx>
 #include "vcl/helper.hxx"
 #include "vcl/ppdparser.hxx"
+#include <boost/scoped_array.hpp>
 
 using ::rtl::Bootstrap;
 
@@ -284,15 +285,15 @@ bool psp::convertPfbToPfa( ::osl::File& rInFile, ::osl::File& rOutFile )
         }
         else if( nType == 1 || nType == 2 )
         {
-            unsigned char* pBuffer = new unsigned char[ nBytesToRead+1 ];
+            boost::scoped_array<unsigned char> pBuffer(new unsigned char[ nBytesToRead+1 ]);
 
-            if( ! rInFile.read( pBuffer, nBytesToRead, nRead ) && nRead == nBytesToRead )
+            if( ! rInFile.read( pBuffer.get(), nBytesToRead, nRead ) && nRead == nBytesToRead )
             {
                 if( nType == 1 )
                 {
                     // ascii data, convert dos lineends( \r\n ) and
                     // m_ac lineends( \r ) to \n
-                    unsigned char * pWriteBuffer = new unsigned char[ nBytesToRead ];
+                    boost::scoped_array<unsigned char> pWriteBuffer(new unsigned char[ nBytesToRead ]);
                     unsigned int nBytesToWrite = 0;
                     for( unsigned int i = 0; i < nBytesToRead; i++ )
                     {
@@ -306,10 +307,8 @@ bool psp::convertPfbToPfa( ::osl::File& rInFile, ::osl::File& rOutFile )
                         else
                             pWriteBuffer[ nBytesToWrite++ ] = '\n';
                     }
-                    if( rOutFile.write( pWriteBuffer, nBytesToWrite, nRead ) || nRead != nBytesToWrite )
+                    if( rOutFile.write( pWriteBuffer.get(), nBytesToWrite, nRead ) || nRead != nBytesToWrite )
                         bSuccess = false;
-
-                    delete [] pWriteBuffer;
                 }
                 else
                 {
@@ -337,8 +336,6 @@ bool psp::convertPfbToPfa( ::osl::File& rInFile, ::osl::File& rOutFile )
             }
             else
                 bSuccess = false;
-
-            delete [] pBuffer;
         }
         else if( nType == 3 )
             bEof = true;
diff --git a/vcl/source/app/dbggui.cxx b/vcl/source/app/dbggui.cxx
index ac2cdd0..81c32b2 100644
--- a/vcl/source/app/dbggui.cxx
+++ b/vcl/source/app/dbggui.cxx
@@ -58,6 +58,7 @@
 
 #include <map>
 #include <algorithm>
+#include <boost/scoped_array.hpp>
 #include <boost/scoped_ptr.hpp>
 
 using namespace ::com::sun::star;
@@ -1090,8 +1091,8 @@ void DbgDialogTest( Window* pWindow )
     if ( !pGetChild )
         return;
 
-    Rectangle*  pRectAry = (Rectangle*)new long[(sizeof(Rectangle)*nChildCount)/sizeof(long)];
-    memset( pRectAry, 0, sizeof(Rectangle)*nChildCount );
+    boost::scoped_array<Rectangle> pRectAry((Rectangle*)new long[(sizeof(Rectangle)*nChildCount)/sizeof(long)]);
+    memset( pRectAry.get(), 0, sizeof(Rectangle)*nChildCount );
 
     if ( pWindow->IsDialog() )
     {
@@ -1433,8 +1434,6 @@ void DbgDialogTest( Window* pWindow )
         pGetChild = pGetChild->GetWindow( WINDOW_NEXT );
         i++;
     }
-
-    delete [] pRectAry;
 }
 
 #ifndef WNT
diff --git a/vcl/source/control/edit.cxx b/vcl/source/control/edit.cxx
index 0a2170e..0803532 100644
--- a/vcl/source/control/edit.cxx
+++ b/vcl/source/control/edit.cxx
@@ -67,6 +67,7 @@
 #include <vcl/unohelp2.hxx>
 
 #include <officecfg/Office/Common.hxx>
+#include <boost/scoped_array.hpp>
 
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::uno;
@@ -486,15 +487,15 @@ void Edit::ImplRepaint(bool bLayout)
     sal_Int32 nLen = aText.getLength();
 
     sal_Int32   nDXBuffer[256];
-    sal_Int32*  pDXBuffer = NULL;
+    boost::scoped_array<sal_Int32> pDXBuffer;
     sal_Int32*  pDX = nDXBuffer;
 
     if( !aText.isEmpty() )
     {
         if( (size_t) (2*aText.getLength()) > SAL_N_ELEMENTS(nDXBuffer) )
         {
-            pDXBuffer = new sal_Int32[2*(aText.getLength()+1)];
-            pDX = pDXBuffer;
+            pDXBuffer.reset(new sal_Int32[2*(aText.getLength()+1)]);
+            pDX = pDXBuffer.get();
         }
 
         GetCaretPositions( aText, pDX, 0, nLen );
@@ -512,7 +513,6 @@ void Edit::ImplRepaint(bool bLayout)
 
         DrawText( aPos, aText, 0, nLen, pVector, pDisplayText );
 
-        delete [] pDXBuffer;
         return;
     }
 
@@ -693,8 +693,6 @@ void Edit::ImplRepaint(bool bLayout)
 
     if ( bVisCursor && ( !mpIMEInfos || mpIMEInfos->bCursor ) )
         pCursor->Show();
-
-    delete [] pDXBuffer;
 }
 
 void Edit::ImplDelete( const Selection& rSelection, sal_uInt8 nDirection, sal_uInt8 nMode )
@@ -1089,15 +1087,15 @@ void Edit::ImplShowCursor( bool bOnlyIfVisible )
     long nTextPos = 0;
 
     sal_Int32   nDXBuffer[256];
-    sal_Int32*  pDXBuffer = NULL;
+    boost::scoped_array<sal_Int32> pDXBuffer;
     sal_Int32*  pDX = nDXBuffer;
 
     if( !aText.isEmpty() )
     {
         if( (size_t) (2*aText.getLength()) > SAL_N_ELEMENTS(nDXBuffer) )
         {
-            pDXBuffer = new sal_Int32[2*(aText.getLength()+1)];
-            pDX = pDXBuffer;
+            pDXBuffer.reset(new sal_Int32[2*(aText.getLength()+1)]);
+            pDX = pDXBuffer.get();
         }
 
         GetCaretPositions( aText, pDX, 0, aText.getLength() );
@@ -1153,9 +1151,6 @@ void Edit::ImplShowCursor( bool bOnlyIfVisible )
     pCursor->SetPos( Point( nCursorPosX, nCursorPosY ) );
     pCursor->SetSize( Size( nCursorWidth, nTextHeight ) );
     pCursor->Show();
-
-    if( pDXBuffer )
-        delete [] pDXBuffer;
 }
 
 void Edit::ImplAlign()
@@ -1208,12 +1203,12 @@ sal_Int32 Edit::ImplGetCharPos( const Point& rWindowPos ) const
     OUString aText = ImplGetText();
 
     sal_Int32   nDXBuffer[256];
-    sal_Int32*  pDXBuffer = NULL;
+    boost::scoped_array<sal_Int32> pDXBuffer;
     sal_Int32*  pDX = nDXBuffer;
     if( (size_t) (2*aText.getLength()) > SAL_N_ELEMENTS(nDXBuffer) )
     {
-        pDXBuffer = new sal_Int32[2*(aText.getLength()+1)];
-        pDX = pDXBuffer;
+        pDXBuffer.reset(new sal_Int32[2*(aText.getLength()+1)]);
+        pDX = pDXBuffer.get();
     }
 
     GetCaretPositions( aText, pDX, 0, aText.getLength() );
@@ -1255,9 +1250,6 @@ sal_Int32 Edit::ImplGetCharPos( const Point& rWindowPos ) const
             nIndex = EDIT_NOLIMIT;
     }
 
-    if( pDXBuffer )
-        delete [] pDXBuffer;
-
     return nIndex;
 }
 
@@ -2177,15 +2169,15 @@ void Edit::Command( const CommandEvent& rCEvt )
         {
             OUString aText = ImplGetText();
             sal_Int32   nDXBuffer[256];
-            sal_Int32*  pDXBuffer = NULL;
+            boost::scoped_array<sal_Int32> pDXBuffer;
             sal_Int32*  pDX = nDXBuffer;
 
             if( !aText.isEmpty() )
             {
                 if( (size_t) (2*aText.getLength()) > SAL_N_ELEMENTS(nDXBuffer) )
                 {
-                    pDXBuffer = new sal_Int32[2*(aText.getLength()+1)];
-                    pDX = pDXBuffer;
+                    pDXBuffer.reset(new sal_Int32[2*(aText.getLength()+1)]);
+                    pDX = pDXBuffer.get();
                 }
 
                 GetCaretPositions( aText, pDX, 0, aText.getLength() );
@@ -2193,16 +2185,14 @@ void Edit::Command( const CommandEvent& rCEvt )
             long    nTH = GetTextHeight();
             Point   aPos( mnXOffset, ImplGetTextYPosition() );
 
-            Rectangle* aRects = new Rectangle[ mpIMEInfos->nLen ];
+            boost::scoped_array<Rectangle> aRects(new Rectangle[ mpIMEInfos->nLen ]);
             for ( int nIndex = 0; nIndex < mpIMEInfos->nLen; ++nIndex )
             {
                 Rectangle aRect( aPos, Size( 10, nTH ) );
                 aRect.Left() = pDX[2*(nIndex+mpIMEInfos->nPos)] + mnXOffset + ImplGetExtraOffset();
                 aRects[ nIndex ] = aRect;
             }
-            SetCompositionCharRect( aRects, mpIMEInfos->nLen );
-            delete[] aRects;
-            delete[] pDXBuffer;
+            SetCompositionCharRect( aRects.get(), mpIMEInfos->nLen );
         }
     }
     else


More information about the Libreoffice-commits mailing list