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

Takeshi Abe tabe at fixedpoint.jp
Wed Apr 30 08:54:15 PDT 2014


 sc/source/core/data/documen4.cxx |   24 +++++++++---------------
 sc/source/core/tool/addincol.cxx |   25 ++++++++++---------------
 sc/source/core/tool/appoptio.cxx |    7 +++----
 sc/source/core/tool/consoli.cxx  |   12 +++++-------
 sc/source/core/tool/detfunc.cxx  |   13 +++++++------
 5 files changed, 34 insertions(+), 47 deletions(-)

New commits:
commit ecec7cea259e7310cb6da33bea797c98a635a2b3
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date:   Thu May 1 00:51:44 2014 +0900

    Avoid possible memory leaks in case of exceptions
    
    Change-Id: Id6590e6c1d3ec1640ebf55d348670953450dd419

diff --git a/sc/source/core/data/documen4.cxx b/sc/source/core/data/documen4.cxx
index 88af3ce..a156c3b 100644
--- a/sc/source/core/data/documen4.cxx
+++ b/sc/source/core/data/documen4.cxx
@@ -1186,9 +1186,9 @@ void ScDocument::CompareDocument( ScDocument& rOtherDoc )
                                         aProText.makeStringAndClear(), 3*nThisEndRow );  // 2x FindOrder, 1x hier
             long nProgressStart = 2*nThisEndRow;                    // start fuer hier
 
-            SCCOLROW* pTempRows = new SCCOLROW[nThisEndRow+1];
-            SCCOLROW* pOtherRows = new SCCOLROW[nThisEndRow+1];
-            SCCOLROW* pOtherCols = new SCCOLROW[nThisEndCol+1];
+            boost::scoped_array<SCCOLROW> pTempRows(new SCCOLROW[nThisEndRow+1]);
+            boost::scoped_array<SCCOLROW> pOtherRows(new SCCOLROW[nThisEndRow+1]);
+            boost::scoped_array<SCCOLROW> pOtherCols(new SCCOLROW[nThisEndCol+1]);
 
             //  eingefuegte/geloeschte Spalten/Zeilen finden:
             //  Zwei Versuche:
@@ -1199,14 +1199,14 @@ void ScDocument::CompareDocument( ScDocument& rOtherDoc )
             //! Spalten vergleichen zweimal mit unterschiedlichem nMinGood ???
 
             // 1
-            FindOrder( pTempRows, nThisEndRow, nOtherEndRow, false,
+            FindOrder( pTempRows.get(), nThisEndRow, nOtherEndRow, false,
                         rOtherDoc, nThisTab, nOtherTab, nEndCol, NULL, &aProgress, 0 );
             // 2
-            FindOrder( pOtherCols, nThisEndCol, nOtherEndCol, true,
+            FindOrder( pOtherCols.get(), nThisEndCol, nOtherEndCol, true,
                         rOtherDoc, nThisTab, nOtherTab, nEndRow, NULL, NULL, 0 );
-            FindOrder( pOtherRows, nThisEndRow, nOtherEndRow, false,
+            FindOrder( pOtherRows.get(), nThisEndRow, nOtherEndRow, false,
                         rOtherDoc, nThisTab, nOtherTab, nThisEndCol,
-                        pOtherCols, &aProgress, nThisEndRow );
+                       pOtherCols.get(), &aProgress, nThisEndRow );
 
             sal_uLong nMatch1 = 0;  // pTempRows, keine Spalten
             for (nThisRow = 0; nThisRow<=nThisEndRow; nThisRow++)
@@ -1220,7 +1220,7 @@ void ScDocument::CompareDocument( ScDocument& rOtherDoc )
                 if (ValidRow(pOtherRows[nThisRow]))
                     nMatch2 += SC_DOCCOMP_MAXDIFF -
                                RowDifferences( nThisRow, nThisTab, rOtherDoc, pOtherRows[nThisRow],
-                                                nOtherTab, nThisEndCol, pOtherCols );
+                                               nOtherTab, nThisEndCol, pOtherCols.get() );
 
             if ( nMatch1 >= nMatch2 )           // ohne Spalten ?
             {
@@ -1229,9 +1229,7 @@ void ScDocument::CompareDocument( ScDocument& rOtherDoc )
                     pOtherCols[nThisCol] = nThisCol;
 
                 //  Zeilenarrays vertauschen (geloescht werden sowieso beide)
-                SCCOLROW* pSwap = pTempRows;
-                pTempRows = pOtherRows;
-                pOtherRows = pSwap;
+                pTempRows.swap(pOtherRows);
             }
             else
             {
@@ -1351,10 +1349,6 @@ void ScDocument::CompareDocument( ScDocument& rOtherDoc )
                 }
                 aProgress.SetStateOnPercent(nProgressStart+nThisRow);
             }
-
-            delete[] pOtherCols;
-            delete[] pOtherRows;
-            delete[] pTempRows;
         }
     }
 }
diff --git a/sc/source/core/tool/addincol.cxx b/sc/source/core/tool/addincol.cxx
index 77f6795..50cf247 100644
--- a/sc/source/core/tool/addincol.cxx
+++ b/sc/source/core/tool/addincol.cxx
@@ -52,6 +52,7 @@
 #include "funcdesc.hxx"
 #include "svl/sharedstring.hxx"
 #include "formulaopt.hxx"
+#include <boost/scoped_array.hpp>
 
 using namespace com::sun::star;
 
@@ -489,7 +490,7 @@ void ScUnoAddInCollection::ReadConfiguration()
 
                 // get argument info
 
-                ScAddInArgDesc* pVisibleArgs = NULL;
+                boost::scoped_array<ScAddInArgDesc> pVisibleArgs;
                 long nVisibleCount = 0;
                 long nCallerPos = SC_CALLERPOS_NONE;
 
@@ -532,7 +533,7 @@ void ScUnoAddInCollection::ReadConfiguration()
                         aDesc.bOptional = false;
 
                         nVisibleCount = nArgumentCount;
-                        pVisibleArgs = new ScAddInArgDesc[nVisibleCount];
+                        pVisibleArgs.reset(new ScAddInArgDesc[nVisibleCount]);
 
                         nIndex = 0;
                         for ( nArgument = 0; nArgument < nArgumentCount; nArgument++ )
@@ -560,7 +561,7 @@ void ScUnoAddInCollection::ReadConfiguration()
                     aFuncName, aLocalName, aDescription,
                     nCategory, sHelpId,
                     xFunc, aObject,
-                    nVisibleCount, pVisibleArgs, nCallerPos );
+                    nVisibleCount, pVisibleArgs.get(), nCallerPos );
 
                 pData->SetCompNames( aCompNames );
 
@@ -578,8 +579,6 @@ void ScUnoAddInCollection::ReadConfiguration()
                         ScAddInHashMap::value_type(
                             pData->GetUpperLocal(),
                             pData ) );
-
-                delete[] pVisibleArgs;
             }
         }
     }
@@ -898,11 +897,11 @@ void ScUnoAddInCollection::ReadFromAddIn( const uno::Reference<uno::XInterface>&
                                     aDescription = "###";
                                 }
 
-                                ScAddInArgDesc* pVisibleArgs = NULL;
+                                boost::scoped_array<ScAddInArgDesc> pVisibleArgs;
                                 if ( nVisibleCount > 0 )
                                 {
                                     ScAddInArgDesc aDesc;
-                                    pVisibleArgs = new ScAddInArgDesc[nVisibleCount];
+                                    pVisibleArgs.reset(new ScAddInArgDesc[nVisibleCount]);
                                     long nDestPos = 0;
                                     for (nParamPos=0; nParamPos<nParamCount; nParamPos++)
                                     {
@@ -953,7 +952,7 @@ void ScUnoAddInCollection::ReadFromAddIn( const uno::Reference<uno::XInterface>&
                                     aFuncName, aLocalName, aDescription,
                                     nCategory, sHelpId,
                                     xFunc, aObject,
-                                    nVisibleCount, pVisibleArgs, nCallerPos );
+                                    nVisibleCount, pVisibleArgs.get(), nCallerPos );
 
                                 const ScUnoAddInFuncData* pData =
                                     ppFuncData[nFuncPos+nOld];
@@ -969,8 +968,6 @@ void ScUnoAddInCollection::ReadFromAddIn( const uno::Reference<uno::XInterface>&
                                         ScAddInHashMap::value_type(
                                             pData->GetUpperLocal(),
                                             pData ) );
-
-                                delete[] pVisibleArgs;
                             }
                         }
                     }
@@ -1090,11 +1087,11 @@ void ScUnoAddInCollection::UpdateFromAddIn( const uno::Reference<uno::XInterface
                     }
                     if (bValid)
                     {
-                        ScAddInArgDesc* pVisibleArgs = NULL;
+                        boost::scoped_array<ScAddInArgDesc> pVisibleArgs;
                         if ( nVisibleCount > 0 )
                         {
                             ScAddInArgDesc aDesc;
-                            pVisibleArgs = new ScAddInArgDesc[nVisibleCount];
+                            pVisibleArgs.reset(new ScAddInArgDesc[nVisibleCount]);
                             long nDestPos = 0;
                             for (nParamPos=0; nParamPos<nParamCount; nParamPos++)
                             {
@@ -1129,13 +1126,11 @@ void ScUnoAddInCollection::UpdateFromAddIn( const uno::Reference<uno::XInterface
                         }
 
                         pOldData->SetFunction( xFunc, aObject );
-                        pOldData->SetArguments( nVisibleCount, pVisibleArgs );
+                        pOldData->SetArguments( nVisibleCount, pVisibleArgs.get() );
                         pOldData->SetCallerPos( nCallerPos );
 
                         if ( pFunctionList )
                             lcl_UpdateFunctionList( *pFunctionList, *pOldData );
-
-                        delete[] pVisibleArgs;
                     }
                 }
             }
diff --git a/sc/source/core/tool/appoptio.cxx b/sc/source/core/tool/appoptio.cxx
index bc2cf53..eb9f5d3 100644
--- a/sc/source/core/tool/appoptio.cxx
+++ b/sc/source/core/tool/appoptio.cxx
@@ -30,6 +30,7 @@
 #include "sc.hrc"
 #include <formula/compiler.hrc>
 #include "miscuno.hxx"
+#include <boost/scoped_array.hpp>
 
 using namespace utl;
 using namespace com::sun::star::uno;
@@ -138,13 +139,11 @@ static void lcl_SetLastFunctions( ScAppOptions& rOpt, const Any& rValue )
         if ( nCount < USHRT_MAX )
         {
             const sal_Int32* pArray = aSeq.getConstArray();
-            sal_uInt16* pUShorts = new sal_uInt16[nCount];
+            boost::scoped_array<sal_uInt16> pUShorts(new sal_uInt16[nCount]);
             for (long i=0; i<nCount; i++)
                 pUShorts[i] = (sal_uInt16) pArray[i];
 
-            rOpt.SetLRUFuncList( pUShorts, sal::static_int_cast<sal_uInt16>(nCount) );
-
-            delete[] pUShorts;
+            rOpt.SetLRUFuncList( pUShorts.get(), sal::static_int_cast<sal_uInt16>(nCount) );
         }
     }
 }
diff --git a/sc/source/core/tool/consoli.cxx b/sc/source/core/tool/consoli.cxx
index 1b5bed4..7c897c0 100644
--- a/sc/source/core/tool/consoli.cxx
+++ b/sc/source/core/tool/consoli.cxx
@@ -28,6 +28,7 @@
 
 #include <math.h>
 #include <string.h>
+#include <boost/scoped_array.hpp>
 
 #define SC_CONS_NOTFOUND    -1
 
@@ -512,11 +513,11 @@ void ScConsData::AddData( ScDocument* pSrcDoc, SCTAB nTab,
     if (bColByName) ++nStartRow;
     if (bRowByName) ++nStartCol;
     OUString aTitle;
-    SCCOL*  pDestCols = NULL;
-    SCROW*  pDestRows = NULL;
+    boost::scoped_array<SCCOL> pDestCols;
+    boost::scoped_array<SCROW> pDestRows;
     if (bColByName)
     {
-        pDestCols = new SCCOL[nCol2-nStartCol+1];
+        pDestCols.reset(new SCCOL[nCol2-nStartCol+1]);
         for (nCol=nStartCol; nCol<=nCol2; nCol++)
         {
             aTitle = pSrcDoc->GetString(nCol, nRow1, nTab);
@@ -537,7 +538,7 @@ void ScConsData::AddData( ScDocument* pSrcDoc, SCTAB nTab,
     }
     if (bRowByName)
     {
-        pDestRows = new SCROW[nRow2-nStartRow+1];
+        pDestRows.reset(new SCROW[nRow2-nStartRow+1]);
         for (nRow=nStartRow; nRow<=nRow2; nRow++)
         {
             aTitle = pSrcDoc->GetString(nCol1, nRow, nTab);
@@ -607,9 +608,6 @@ void ScConsData::AddData( ScDocument* pSrcDoc, SCTAB nTab,
             }
         }
     }
-
-    delete[] pDestCols;
-    delete[] pDestRows;
 }
 
 //  vorher testen, wieviele Zeilen eingefuegt werden (fuer Undo)
diff --git a/sc/source/core/tool/detfunc.cxx b/sc/source/core/tool/detfunc.cxx
index bb7df21..14d6aae 100644
--- a/sc/source/core/tool/detfunc.cxx
+++ b/sc/source/core/tool/detfunc.cxx
@@ -70,6 +70,7 @@
 #include "cellvalue.hxx"
 
 #include <vector>
+#include <boost/scoped_array.hpp>
 
 using ::std::vector;
 
@@ -670,7 +671,7 @@ void ScDetectiveFunc::DeleteArrowsAt( SCCOL nCol, SCROW nRow, bool bDestPnt )
     if (nObjCount)
     {
         long nDelCount = 0;
-        SdrObject** ppObj = new SdrObject*[nObjCount];
+        boost::scoped_array<SdrObject*> ppObj(new SdrObject*[nObjCount]);
 
         SdrObjListIter aIter( *pPage, IM_FLAT );
         SdrObject* pObject = aIter.Next();
@@ -693,7 +694,7 @@ void ScDetectiveFunc::DeleteArrowsAt( SCCOL nCol, SCROW nRow, bool bDestPnt )
         for (i=1; i<=nDelCount; i++)
             pPage->RemoveObject( ppObj[nDelCount-i]->GetOrdNum() );
 
-        delete[] ppObj;
+        ppObj.reset();
 
         Modified();
     }
@@ -734,7 +735,7 @@ void ScDetectiveFunc::DeleteBox( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nR
     if (nObjCount)
     {
         long nDelCount = 0;
-        SdrObject** ppObj = new SdrObject*[nObjCount];
+        boost::scoped_array<SdrObject*> ppObj(new SdrObject*[nObjCount]);
 
         SdrObjListIter aIter( *pPage, IM_FLAT );
         SdrObject* pObject = aIter.Next();
@@ -759,7 +760,7 @@ void ScDetectiveFunc::DeleteBox( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nR
         for (i=1; i<=nDelCount; i++)
             pPage->RemoveObject( ppObj[nDelCount-i]->GetOrdNum() );
 
-        delete[] ppObj;
+        ppObj.reset();
 
         Modified();
     }
@@ -1245,7 +1246,7 @@ bool ScDetectiveFunc::DeleteAll( ScDetectiveDelete eWhat )
     sal_uLong   nObjCount = pPage->GetObjCount();
     if (nObjCount)
     {
-        SdrObject** ppObj = new SdrObject*[nObjCount];
+        boost::scoped_array<SdrObject*> ppObj(new SdrObject*[nObjCount]);
 
         SdrObjListIter aIter( *pPage, IM_FLAT );
         SdrObject* pObject = aIter.Next();
@@ -1283,7 +1284,7 @@ bool ScDetectiveFunc::DeleteAll( ScDetectiveDelete eWhat )
         for (i=1; i<=nDelCount; i++)
             pPage->RemoveObject( ppObj[nDelCount-i]->GetOrdNum() );
 
-        delete[] ppObj;
+        ppObj.reset();
 
         Modified();
     }


More information about the Libreoffice-commits mailing list