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

Takeshi Abe tabe at fixedpoint.jp
Tue Mar 25 04:12:07 PDT 2014


 basic/source/runtime/methods.cxx  |   12 +++++-------
 basic/source/runtime/methods1.cxx |    7 ++++---
 basic/source/runtime/runtime.cxx  |   12 +++++-------
 basic/source/sbx/sbxdec.cxx       |    7 +++----
 4 files changed, 17 insertions(+), 21 deletions(-)

New commits:
commit dd52330db6551c3e96fce5ba17ff823882d158fd
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date:   Tue Mar 25 20:07:48 2014 +0900

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

diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx
index 0cc3db1..b35d8d6 100644
--- a/basic/source/runtime/methods.cxx
+++ b/basic/source/runtime/methods.cxx
@@ -55,6 +55,7 @@
 #include <com/sun/star/script/XErrorQuery.hpp>
 #include <ooo/vba/XHelperInterface.hpp>
 #include <com/sun/star/bridge/oleautomation/XAutomationObject.hpp>
+#include <boost/scoped_array.hpp>
 
 using namespace comphelper;
 using namespace osl;
@@ -445,28 +446,25 @@ RTLFUNC(CurDir)
     const int PATH_INCR = 250;
 
     int nSize = PATH_INCR;
-    char* pMem;
+    boost::scoped_array<char> pMem;
     while( true )
       {
-        pMem = new char[nSize];
+        pMem.reset(new char[nSize]);
         if( !pMem )
           {
             StarBASIC::Error( SbERR_NO_MEMORY );
             return;
           }
-        if( getcwd( pMem, nSize-1 ) != NULL )
+        if( getcwd( pMem.get(), nSize-1 ) != NULL )
           {
-            rPar.Get(0)->PutString( OUString::createFromAscii(pMem) );
-            delete [] pMem;
+            rPar.Get(0)->PutString( OUString::createFromAscii(pMem.get()) );
             return;
           }
         if( errno != ERANGE )
           {
             StarBASIC::Error( SbERR_INTERNAL_ERROR );
-            delete [] pMem;
             return;
           }
-        delete [] pMem;
         nSize += PATH_INCR;
       };
 
diff --git a/basic/source/runtime/methods1.cxx b/basic/source/runtime/methods1.cxx
index 6b52e28..00c8b7d 100644
--- a/basic/source/runtime/methods1.cxx
+++ b/basic/source/runtime/methods1.cxx
@@ -55,6 +55,7 @@
 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
 #include <com/sun/star/i18n/LocaleCalendar.hpp>
 #include <com/sun/star/sheet/XFunctionAccess.hpp>
+#include <boost/scoped_array.hpp>
 
 using namespace comphelper;
 using namespace com::sun::star::i18n;
@@ -1277,9 +1278,9 @@ void PutGet( SbxArray& rPar, sal_Bool bPut )
     {
         sal_Size nFPos = pStrm->Tell();
         short nDims = pArr->GetDims();
-        short* pDims = new short[ nDims ];
-        bRet = lcl_WriteReadSbxArray(*pArr,pStrm,!bRandom,nDims,pDims,bPut);
-        delete [] pDims;
+        boost::scoped_array<short> pDims(new short[ nDims ]);
+        bRet = lcl_WriteReadSbxArray(*pArr,pStrm,!bRandom,nDims,pDims.get(),bPut);
+        pDims.reset();
         if( nBlockLen )
             pStrm->Seek( nFPos + nBlockLen );
     }
diff --git a/basic/source/runtime/runtime.cxx b/basic/source/runtime/runtime.cxx
index 3ee4b93..66026e0 100644
--- a/basic/source/runtime/runtime.cxx
+++ b/basic/source/runtime/runtime.cxx
@@ -66,6 +66,7 @@
 #include "sbintern.hxx"
 #include "sbunoobj.hxx"
 #include <basic/codecompletecache.hxx>
+#include <boost/scoped_array.hpp>
 
 using com::sun::star::uno::Reference;
 
@@ -4453,9 +4454,9 @@ void SbiRuntime::StepDCREATE_IMPL( sal_uInt32 nOp1, sal_uInt32 nOp2 )
         bool bRangeError = false;
 
         // Store dims to use them for copying later
-        sal_Int32* pLowerBounds = new sal_Int32[nDims];
-        sal_Int32* pUpperBounds = new sal_Int32[nDims];
-        sal_Int32* pActualIndices = new sal_Int32[nDims];
+        boost::scoped_array<sal_Int32> pLowerBounds(new sal_Int32[nDims]);
+        boost::scoped_array<sal_Int32> pUpperBounds(new sal_Int32[nDims]);
+        boost::scoped_array<sal_Int32> pActualIndices(new sal_Int32[nDims]);
         if( nDimsOld != nDimsNew )
         {
             bRangeError = true;
@@ -4488,11 +4489,8 @@ void SbiRuntime::StepDCREATE_IMPL( sal_uInt32 nOp1, sal_uInt32 nOp2 )
             // (It would be faster to work on the flat internal data array of an
             // SbyArray but this solution is clearer and easier)
             implCopyDimArray_DCREATE( pArray, pOldArray, nDims - 1,
-                0, pActualIndices, pLowerBounds, pUpperBounds );
+                                      0, pActualIndices.get(), pLowerBounds.get(), pUpperBounds.get() );
         }
-        delete [] pUpperBounds;
-        delete [] pLowerBounds;
-        delete [] pActualIndices;
         refRedimpArray = NULL;
     }
 }
diff --git a/basic/source/sbx/sbxdec.cxx b/basic/source/sbx/sbxdec.cxx
index 276b788..c9fd347 100644
--- a/basic/source/sbx/sbxdec.cxx
+++ b/basic/source/sbx/sbxdec.cxx
@@ -23,7 +23,7 @@
 #include "sbxconv.hxx"
 
 #include <com/sun/star/bridge/oleautomation/Decimal.hpp>
-
+#include <boost/scoped_array.hpp>
 
 // Implementation SbxDecimal
 SbxDecimal::SbxDecimal( void )
@@ -206,7 +206,7 @@ bool SbxDecimal::setString( OUString* pOUString )
     if( cDecimalSep != '.' || cThousandSep != ',' )
     {
         int nLen = pOUString->getLength();
-        sal_Unicode* pBuffer = new sal_Unicode[nLen +  1];
+        boost::scoped_array<sal_Unicode> pBuffer(new sal_Unicode[nLen +  1]);
         pBuffer[nLen] = 0;
 
         const sal_Unicode* pSrc = pOUString->getStr();
@@ -224,8 +224,7 @@ bool SbxDecimal::setString( OUString* pOUString )
                 pBuffer[i] = ',';
             i++;
         }
-        hResult = VarDecFromStr( (OLECHAR*)pBuffer, nLANGID, 0, &maDec );
-        delete [] pBuffer;
+        hResult = VarDecFromStr( (OLECHAR*)pBuffer.get(), nLANGID, 0, &maDec );
     }
     else
     {


More information about the Libreoffice-commits mailing list