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

Takeshi Abe tabe at fixedpoint.jp
Fri Apr 25 17:30:17 PDT 2014


 sc/source/core/data/column2.cxx  |    3 +--
 sc/source/core/data/conditio.cxx |   17 +++++++++--------
 sc/source/core/data/documen4.cxx |    8 ++------
 sc/source/core/data/documen8.cxx |   10 ++++------
 sc/source/core/data/drwlayer.cxx |    9 +++------
 5 files changed, 19 insertions(+), 28 deletions(-)

New commits:
commit b08754f3358992387ea0eec7957745f4667ea7eb
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date:   Sat Apr 26 09:25:29 2014 +0900

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

diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index 151f6b0..7cdd62a 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -344,10 +344,9 @@ long ScColumn::GetNeededSize(
         SfxItemSet* pSet = new SfxItemSet( pEngine->GetEmptyItemSet() );
         if ( ScStyleSheet* pPreviewStyle = pDocument->GetPreviewCellStyle( nCol, nRow, nTab ) )
         {
-            ScPatternAttr* pPreviewPattern = new ScPatternAttr( *pPattern );
+            boost::scoped_ptr<ScPatternAttr> pPreviewPattern(new ScPatternAttr( *pPattern ));
             pPreviewPattern->SetStyleSheet(pPreviewStyle);
             pPreviewPattern->FillEditItemSet( pSet, pCondSet );
-            delete pPreviewPattern;
         }
         else
         {
diff --git a/sc/source/core/data/conditio.cxx b/sc/source/core/data/conditio.cxx
index 8ad386a..551da4c 100644
--- a/sc/source/core/data/conditio.cxx
+++ b/sc/source/core/data/conditio.cxx
@@ -42,6 +42,7 @@
 #include "refupdatecontext.hxx"
 #include <svl/sharedstring.hxx>
 #include <svl/sharedstringpool.hxx>
+#include <boost/scoped_ptr.hpp>
 
 using namespace formula;
 
@@ -627,12 +628,12 @@ void ScConditionEntry::Interpret( const ScAddress& rPos )
 
     bool bDirty = false;        //! 1 und 2 getrennt ???
 
-    ScFormulaCell* pTemp1 = NULL;
+    boost::scoped_ptr<ScFormulaCell> pTemp1;
     ScFormulaCell* pEff1 = pFCell1;
     if ( bRelRef1 )
     {
-        pTemp1 = pFormula1 ? new ScFormulaCell(mpDoc, rPos, *pFormula1) : new ScFormulaCell(mpDoc, rPos);
-        pEff1 = pTemp1;
+        pTemp1.reset(pFormula1 ? new ScFormulaCell(mpDoc, rPos, *pFormula1) : new ScFormulaCell(mpDoc, rPos));
+        pEff1 = pTemp1.get();
     }
     if ( pEff1 )
     {
@@ -655,14 +656,14 @@ void ScConditionEntry::Interpret( const ScAddress& rPos )
             }
         }
     }
-    delete pTemp1;
+    pTemp1.reset();
 
-    ScFormulaCell* pTemp2 = NULL;
+    boost::scoped_ptr<ScFormulaCell> pTemp2;
     ScFormulaCell* pEff2 = pFCell2; //@ 1!=2
     if ( bRelRef2 )
     {
-        pTemp2 = pFormula2 ? new ScFormulaCell(mpDoc, rPos, *pFormula2) : new ScFormulaCell(mpDoc, rPos);
-        pEff2 = pTemp2;
+        pTemp2.reset(pFormula2 ? new ScFormulaCell(mpDoc, rPos, *pFormula2) : new ScFormulaCell(mpDoc, rPos));
+        pEff2 = pTemp2.get();
     }
     if ( pEff2 )
     {
@@ -684,7 +685,7 @@ void ScConditionEntry::Interpret( const ScAddress& rPos )
             }
         }
     }
-    delete pTemp2;
+    pTemp2.reset();
 
     //  wenn IsRunning, bleiben die letzten Werte erhalten
 
diff --git a/sc/source/core/data/documen4.cxx b/sc/source/core/data/documen4.cxx
index 7e378c1..88af3ce 100644
--- a/sc/source/core/data/documen4.cxx
+++ b/sc/source/core/data/documen4.cxx
@@ -45,6 +45,7 @@
 #include "tokenarray.hxx"
 #include "scmatrix.hxx"
 #include <tokenstringcontext.hxx>
+#include <boost/scoped_array.hpp>
 
 using namespace formula;
 
@@ -1099,7 +1100,7 @@ void ScDocument::CompareDocument( ScDocument& rOtherDoc )
 
     SCTAB nThisCount = GetTableCount();
     SCTAB nOtherCount = rOtherDoc.GetTableCount();
-    SCTAB* pOtherTabs = new SCTAB[nThisCount];
+    boost::scoped_array<SCTAB> pOtherTabs(new SCTAB[nThisCount]);
     SCTAB nThisTab;
 
     //  Tabellen mit gleichen Namen vergleichen
@@ -1356,11 +1357,6 @@ void ScDocument::CompareDocument( ScDocument& rOtherDoc )
             delete[] pTempRows;
         }
     }
-
-    //! Inhalt von eingefuegten / geloeschten Tabellen ???
-    //! Aktionen fuer eingefuegte / geloeschte Tabellen ???
-
-    delete[] pOtherTabs;
 }
 
 
diff --git a/sc/source/core/data/documen8.cxx b/sc/source/core/data/documen8.cxx
index 5ab1e31..316738a 100644
--- a/sc/source/core/data/documen8.cxx
+++ b/sc/source/core/data/documen8.cxx
@@ -1176,7 +1176,7 @@ void ScDocument::TransliterateText( const ScMarkData& rMultiMark, sal_Int32 nTyp
     bool bConsiderLanguage = aTranslitarationWrapper.needLanguageForTheMode();
     sal_uInt16 nLanguage = LANGUAGE_SYSTEM;
 
-    ScEditEngineDefaulter* pEngine = NULL;        // not using pEditEngine member because of defaults
+    boost::scoped_ptr<ScEditEngineDefaulter> pEngine;        // not using pEditEngine member because of defaults
 
     SCTAB nCount = GetTableCount();
     ScMarkData::const_iterator itr = rMultiMark.begin(), itrEnd = rMultiMark.end();
@@ -1204,17 +1204,16 @@ void ScDocument::TransliterateText( const ScMarkData& rMultiMark, sal_Int32 nTyp
                      ( nType == i18n::TransliterationModulesExtra::SENTENCE_CASE || nType == i18n::TransliterationModulesExtra::TITLE_CASE)))
                 {
                     if (!pEngine)
-                        pEngine = new ScFieldEditEngine(this, GetEnginePool(), GetEditPool());
+                        pEngine.reset(new ScFieldEditEngine(this, GetEnginePool(), GetEditPool()));
 
                     // defaults from cell attributes must be set so right language is used
                     const ScPatternAttr* pPattern = GetPattern( nCol, nRow, nTab );
                     SfxItemSet* pDefaults = new SfxItemSet( pEngine->GetEmptyItemSet() );
                     if ( ScStyleSheet* pPreviewStyle = GetPreviewCellStyle( nCol, nRow, nTab ) )
                     {
-                        ScPatternAttr* pPreviewPattern = new ScPatternAttr( *pPattern );
+                        boost::scoped_ptr<ScPatternAttr> pPreviewPattern(new ScPatternAttr( *pPattern ));
                         pPreviewPattern->SetStyleSheet(pPreviewStyle);
                         pPreviewPattern->FillEditItemSet( pDefaults );
-                        delete pPreviewPattern;
                     }
                     else
                     {
@@ -1239,7 +1238,7 @@ void ScDocument::TransliterateText( const ScMarkData& rMultiMark, sal_Int32 nTyp
 
                     if ( pEngine->IsModified() )
                     {
-                        ScEditAttrTester aTester( pEngine );
+                        ScEditAttrTester aTester( pEngine.get() );
                         if ( aTester.NeedsObject() )
                         {
                             // remove defaults (paragraph attributes) before creating text object
@@ -1285,7 +1284,6 @@ void ScDocument::TransliterateText( const ScMarkData& rMultiMark, sal_Int32 nTyp
                 bFound = GetNextMarkedCell( nCol, nRow, nTab, rMultiMark );
             }
         }
-    delete pEngine;
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/drwlayer.cxx b/sc/source/core/data/drwlayer.cxx
index d807c16..57bc088 100644
--- a/sc/source/core/data/drwlayer.cxx
+++ b/sc/source/core/data/drwlayer.cxx
@@ -77,6 +77,7 @@
 #include "basegfx/matrix/b2dhommatrix.hxx"
 
 #include <vcl/field.hxx>
+#include <boost/scoped_array.hpp>
 
 #define DET_ARROW_OFFSET    1000
 
@@ -1156,7 +1157,7 @@ void ScDrawLayer::DeleteObjectsInArea( SCTAB nTab, SCCOL nCol1,SCROW nRow1,
         long nDelCount = 0;
         Rectangle aDelRect = pDoc->GetMMRect( nCol1, nRow1, nCol2, nRow2, nTab );
 
-        SdrObject** ppObj = new SdrObject*[nObjCount];
+        boost::scoped_array<SdrObject*> ppObj(new SdrObject*[nObjCount]);
 
         SdrObjListIter aIter( *pPage, IM_FLAT );
         SdrObject* pObject = aIter.Next();
@@ -1181,8 +1182,6 @@ void ScDrawLayer::DeleteObjectsInArea( SCTAB nTab, SCCOL nCol1,SCROW nRow1,
 
         for (i=1; i<=nDelCount; i++)
             pPage->RemoveObject( ppObj[nDelCount-i]->GetOrdNum() );
-
-        delete[] ppObj;
     }
 }
 
@@ -1216,7 +1215,7 @@ void ScDrawLayer::DeleteObjectsInSelection( const ScMarkData& rMark )
                             aMarkRange.aStart.Col(), aMarkRange.aStart.Row(),
                             aMarkRange.aEnd.Col(), aMarkRange.aEnd.Row(), nTab );
 
-                SdrObject** ppObj = new SdrObject*[nObjCount];
+                boost::scoped_array<SdrObject*> ppObj(new SdrObject*[nObjCount]);
 
                 SdrObjListIter aIter( *pPage, IM_FLAT );
                 SdrObject* pObject = aIter.Next();
@@ -1247,8 +1246,6 @@ void ScDrawLayer::DeleteObjectsInSelection( const ScMarkData& rMark )
 
                 for (i=1; i<=nDelCount; i++)
                     pPage->RemoveObject( ppObj[nDelCount-i]->GetOrdNum() );
-
-                delete[] ppObj;
             }
         }
         else


More information about the Libreoffice-commits mailing list