[Libreoffice-commits] .: sc/inc sc/source

Kohei Yoshida kohei at kemper.freedesktop.org
Thu Dec 9 18:00:48 PST 2010


 sc/inc/rangelst.hxx                  |    2 +-
 sc/source/core/data/document.cxx     |    4 ++--
 sc/source/core/data/markdata.cxx     |    4 ++--
 sc/source/core/tool/rangelst.cxx     |   31 +++++++++++++++++++++----------
 sc/source/filter/excel/xiformula.cxx |    2 +-
 sc/source/filter/excel/xihelper.cxx  |    2 +-
 sc/source/filter/excel/xistyle.cxx   |    2 +-
 sc/source/filter/html/htmlpars.cxx   |    4 +---
 sc/source/ui/miscdlgs/acredlin.cxx   |    2 +-
 sc/source/ui/miscdlgs/anyrefdg.cxx   |    2 +-
 sc/source/ui/unoobj/cellsuno.cxx     |    6 +++---
 sc/source/ui/vba/vbaeventshelper.cxx |    2 +-
 12 files changed, 36 insertions(+), 27 deletions(-)

New commits:
commit 3f20fb3ac89dab1042f406c0ce13ad2619eb3d5c
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Thu Dec 9 20:58:11 2010 -0500

    Don't allow client code to call clear() directly, it leaks memory.
    
    Call RemoveAll() instead.  Better yet, I've removed clear() call
    as it's safer this way.

diff --git a/sc/inc/rangelst.hxx b/sc/inc/rangelst.hxx
index cb42c6c..ebc957e 100644
--- a/sc/inc/rangelst.hxx
+++ b/sc/inc/rangelst.hxx
@@ -77,6 +77,7 @@ public:
     size_t			GetCellCount() const;
 
     ScRange*        Remove(size_t nPos);
+    void            RemoveAll();
 
     bool            empty() const;
     size_t          size() const;
@@ -89,7 +90,6 @@ public:
     ScRange*        back();
     const ScRange*  back() const;
     void            push_back(ScRange* p);
-    void            clear();
 
 private:
     ::std::vector<ScRange*> maRanges;
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 5407585..3688ae7 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -1679,7 +1679,7 @@ void ScDocument::CopyTabToClip(SCCOL nCol1, SCROW nRow1,
 
         ScClipParam& rClipParam = pClipDoc->GetClipParam();
         pClipDoc->aDocName = aDocName;
-        rClipParam.maRanges.clear();
+        rClipParam.maRanges.RemoveAll();
         rClipParam.maRanges.Append(ScRange(nCol1, nRow1, 0, nCol2, nRow2, 0));
         pClipDoc->ResetClip( this, nTab );
 
@@ -2467,7 +2467,7 @@ void ScDocument::SetClipArea( const ScRange& rArea, BOOL bCut )
     if (bIsClip)
     {
         ScClipParam& rClipParam = GetClipParam();
-        rClipParam.maRanges.clear();
+        rClipParam.maRanges.RemoveAll();
         rClipParam.maRanges.Append(rArea);
         rClipParam.mbCutMode = bCut;
     }
diff --git a/sc/source/core/data/markdata.cxx b/sc/source/core/data/markdata.cxx
index 456c05a..36d3338 100644
--- a/sc/source/core/data/markdata.cxx
+++ b/sc/source/core/data/markdata.cxx
@@ -369,7 +369,7 @@ void ScMarkData::FillRangeListWithMarks( ScRangeList* pList, BOOL bClear ) const
         return;
 
     if (bClear)
-        pList->clear();
+        pList->RemoveAll();
 
     //!		bei mehreren selektierten Tabellen mehrere Ranges eintragen !!!
 
@@ -406,7 +406,7 @@ void ScMarkData::ExtendRangeListTables( ScRangeList* pList ) const
         return;
 
     ScRangeList aOldList(*pList);
-    pList->clear();					//!	oder die vorhandenen unten weglassen
+    pList->RemoveAll();					//!	oder die vorhandenen unten weglassen
 
     for (SCTAB nTab=0; nTab<=MAXTAB; nTab++)
         if (bTabMarked[nTab])
diff --git a/sc/source/core/tool/rangelst.cxx b/sc/source/core/tool/rangelst.cxx
index aa79098..d828665 100644
--- a/sc/source/core/tool/rangelst.cxx
+++ b/sc/source/core/tool/rangelst.cxx
@@ -47,15 +47,13 @@
 using ::std::vector;
 using ::std::advance;
 using ::std::find_if;
+using ::std::for_each;
 
 // === ScRangeList ====================================================
 
 ScRangeList::~ScRangeList()
 {
-    std::vector<ScRangePtr>::iterator itr = maRanges.begin(), itrEnd = maRanges.end();
-    for (; itr != itrEnd; ++itr)
-        delete *itr;
-    clear();
+    RemoveAll();
 }
 
 USHORT ScRangeList::Parse( const String& rStr, ScDocument* pDoc, USHORT nMask,
@@ -331,7 +329,7 @@ ScRangeList::ScRangeList( const ScRangeList& rList ) :
 
 ScRangeList& ScRangeList::operator=(const ScRangeList& rList)
 {
-    clear();
+    RemoveAll();
     for ( size_t j = 0, nListCount = rList.maRanges.size(); j < nListCount; j++ )
         Append( *rList[ j ] );
     return *this;
@@ -384,6 +382,24 @@ ScRange* ScRangeList::Remove(size_t nPos)
     return p;
 }
 
+namespace {
+
+struct DeleteObject : public ::std::unary_function<void, ScRange*>
+{
+    void operator() (ScRange* p)
+    {
+        delete p;
+    }
+};
+
+}
+
+void ScRangeList::RemoveAll()
+{
+    for_each(maRanges.begin(), maRanges.end(), DeleteObject());
+    maRanges.clear();
+}
+
 bool ScRangeList::empty() const
 {
     return maRanges.empty();
@@ -439,11 +455,6 @@ void ScRangeList::push_back(ScRange* p)
     maRanges.push_back(p);
 }
 
-void ScRangeList::clear()
-{
-    maRanges.clear();
-}
-
 // === ScRangePairList ====================================================
 
 ScRangePairList::~ScRangePairList()
diff --git a/sc/source/filter/excel/xiformula.cxx b/sc/source/filter/excel/xiformula.cxx
index e859d40..4ccb3d6 100644
--- a/sc/source/filter/excel/xiformula.cxx
+++ b/sc/source/filter/excel/xiformula.cxx
@@ -67,7 +67,7 @@ void XclImpFmlaCompImpl::CreateRangeList(
         ScRangeList& rScRanges, XclFormulaType /*eType*/,
         const XclTokenArray& rXclTokArr, XclImpStream& /*rStrm*/ )
 {
-    rScRanges.clear();
+    rScRanges.RemoveAll();
 
     //! evil hack, using old formula import :-)
     if( !rXclTokArr.Empty() )
diff --git a/sc/source/filter/excel/xihelper.cxx b/sc/source/filter/excel/xihelper.cxx
index f01213e..bb17cc6 100644
--- a/sc/source/filter/excel/xihelper.cxx
+++ b/sc/source/filter/excel/xihelper.cxx
@@ -140,7 +140,7 @@ bool XclImpAddressConverter::ConvertRange( ScRange& rScRange,
 void XclImpAddressConverter::ConvertRangeList( ScRangeList& rScRanges,
         const XclRangeList& rXclRanges, SCTAB nScTab, bool bWarn )
 {
-    rScRanges.clear();
+    rScRanges.RemoveAll();
     for( XclRangeList::const_iterator aIt = rXclRanges.begin(), aEnd = rXclRanges.end(); aIt != aEnd; ++aIt )
     {
         ScRange aScRange( ScAddress::UNINITIALIZED );
diff --git a/sc/source/filter/excel/xistyle.cxx b/sc/source/filter/excel/xistyle.cxx
index e459ed1..71838b0 100644
--- a/sc/source/filter/excel/xistyle.cxx
+++ b/sc/source/filter/excel/xistyle.cxx
@@ -1763,7 +1763,7 @@ void XclImpXFRangeBuffer::Initialize()
 {
     maColumns.clear();
     maHyperlinks.clear();
-    maMergeList.clear();
+    maMergeList.RemoveAll();
 }
 
 void XclImpXFRangeBuffer::SetXF( const ScAddress& rScPos, sal_uInt16 nXFIndex, XclImpXFInsertMode eMode )
diff --git a/sc/source/filter/html/htmlpars.cxx b/sc/source/filter/html/htmlpars.cxx
index 7b4cc2b..5e03a9d 100644
--- a/sc/source/filter/html/htmlpars.cxx
+++ b/sc/source/filter/html/htmlpars.cxx
@@ -397,9 +397,7 @@ void ScHTMLLayoutParser::SkipLocked( ScEEParseEntry* pE, BOOL bJoin )
 
 void ScHTMLLayoutParser::Adjust()
 {
-    for (size_t i = 0, n = xLockedList->size(); i < n; ++i)
-        delete xLockedList->at(i);
-    xLockedList->clear();
+    xLockedList->RemoveAll();
 
     ScHTMLAdjustStack aStack;
     ScHTMLAdjustStackEntry* pS;
diff --git a/sc/source/ui/miscdlgs/acredlin.cxx b/sc/source/ui/miscdlgs/acredlin.cxx
index ceb3a80..2640674 100644
--- a/sc/source/ui/miscdlgs/acredlin.cxx
+++ b/sc/source/ui/miscdlgs/acredlin.cxx
@@ -1023,7 +1023,7 @@ IMPL_LINK( ScAcceptChgDlg, FilterHandle, SvxTPFilter*, pRef )
     if(pRef!=NULL)
     {
         ClearView();
-        aRangeList.clear();
+        aRangeList.RemoveAll();
         aRangeList.Parse(pTPFilter->GetRange(),pDoc);
         UpdateView();
     }
diff --git a/sc/source/ui/miscdlgs/anyrefdg.cxx b/sc/source/ui/miscdlgs/anyrefdg.cxx
index 7138938..90277da 100644
--- a/sc/source/ui/miscdlgs/anyrefdg.cxx
+++ b/sc/source/ui/miscdlgs/anyrefdg.cxx
@@ -161,7 +161,7 @@ void ScFormulaReferenceHelper::ShowSimpleReference( const XubString& rStr )
 bool ScFormulaReferenceHelper::ParseWithNames( ScRangeList& rRanges, const String& rStr, ScDocument* pDoc )
 {
     bool bError = false;
-    rRanges.clear();
+    rRanges.RemoveAll();
 
     ScAddress::Details aDetails(pDoc->GetAddressConvention(), 0, 0);
     ScRangeUtil aRangeUtil;
diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx
index 34fa7ac..faa3ead 100644
--- a/sc/source/ui/unoobj/cellsuno.cxx
+++ b/sc/source/ui/unoobj/cellsuno.cxx
@@ -1643,7 +1643,7 @@ void ScCellRangesBase::InitInsertRange(ScDocShell* pDocSh, const ScRange& rR)
 
         ScRange aCellRange(rR);
         aCellRange.Justify();
-        aRanges.clear();
+        aRanges.RemoveAll();
         aRanges.Append( aCellRange );
 
         pDocShell->GetDocument()->AddUnoObject(*this);
@@ -1666,7 +1666,7 @@ void ScCellRangesBase::SetNewRange(const ScRange& rNew)
     ScRange aCellRange(rNew);
     aCellRange.Justify();
 
-    aRanges.clear();
+    aRanges.RemoveAll();
     aRanges.Append( aCellRange );
     RefChanged();
 }
@@ -4563,7 +4563,7 @@ void SAL_CALL ScCellRangesObj::removeByName( const rtl::OUString& aName )
             for (USHORT n=0; n<nCount && !bValid; n++)
                 if (aNamedEntries[n]->GetName() == aNameStr)
                 {
-                    aDiff.clear();
+                    aDiff.RemoveAll();
                     aDiff.Append( aNamedEntries[n]->GetRange() );
                     bValid = TRUE;
                 }
diff --git a/sc/source/ui/vba/vbaeventshelper.cxx b/sc/source/ui/vba/vbaeventshelper.cxx
index 2f32bdc..712621a 100644
--- a/sc/source/ui/vba/vbaeventshelper.cxx
+++ b/sc/source/ui/vba/vbaeventshelper.cxx
@@ -680,7 +680,7 @@ bool ScVbaEventsHelper::isSelectionChanged( const uno::Sequence< uno::Any >& rAr
         maOldSelection = pNewCellRanges->GetRangeList();
         return bChanged;
     }
-    maOldSelection.clear();
+    maOldSelection.RemoveAll();
     return true;
 }
 


More information about the Libreoffice-commits mailing list