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

Markus Mohrhard markus.mohrhard at googlemail.com
Thu Jul 31 13:22:04 PDT 2014


 formula/source/ui/dlg/FormulaHelper.cxx  |    4 +++-
 include/formula/IFunctionDescription.hxx |    5 ++---
 sc/source/core/tool/chartlis.cxx         |   23 ++++++++---------------
 3 files changed, 13 insertions(+), 19 deletions(-)

New commits:
commit 42cd7a8a26201fa1db98d6498198db23abef87fc
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Thu Jul 31 22:09:55 2014 +0200

    fix memory leak around chart listeners
    
    Found by Lsan.
    
    The following pattern leaks memory:
    
    boost::ptr_container x;
    x.release().release();
    
    Change-Id: Iaf52e4f2d6a96266fc6afd65ef8027d80c97a08b

diff --git a/sc/source/core/tool/chartlis.cxx b/sc/source/core/tool/chartlis.cxx
index 1fa991a..be56325 100644
--- a/sc/source/core/tool/chartlis.cxx
+++ b/sc/source/core/tool/chartlis.cxx
@@ -519,39 +519,32 @@ public:
 
 void ScChartListenerCollection::FreeUnused()
 {
-    std::vector<ScChartListener*> aUsed, aUnused;
+    ListenersType aUsed, aUnused;
 
     // First, filter each listener into 'used' and 'unused' categories.
     {
-        ListenersType::iterator it = maListeners.begin(), itEnd = maListeners.end();
-        for (; it != itEnd; ++it)
+        while(!maListeners.empty())
         {
-            ScChartListener* p = it->second;
+            ScChartListener* p = maListeners.begin()->second;
             if (p->IsUno())
             {
                 // We don't delete UNO charts; they are to be deleted separately via FreeUno().
-                aUsed.push_back(p);
+                aUsed.transfer(maListeners.begin(), maListeners);
                 continue;
             }
 
             if (p->IsUsed())
             {
                 p->SetUsed(false);
-                aUsed.push_back(p);
+                aUsed.transfer(maListeners.begin(), maListeners);
             }
             else
-                aUnused.push_back(p);
+                aUnused.transfer(maListeners.begin(), maListeners);
+
         }
     }
 
-    // Release all pointers currently managed by the ptr_map container.
-    maListeners.release().release();
-
-    // Re-insert the listeners we need to keep.
-    std::for_each(aUsed.begin(), aUsed.end(), InsertChartListener(maListeners));
-
-    // Now, delete the ones no longer needed.
-    std::for_each(aUnused.begin(), aUnused.end(), boost::checked_deleter<ScChartListener>());
+    std::swap(aUsed, maListeners);
 }
 
 void ScChartListenerCollection::FreeUno( const uno::Reference< chart::XChartDataChangeEventListener >& rListener,
commit 3d6521280929ecacc53b7c358d29d0b5d31b3462
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Thu Jul 31 21:43:59 2014 +0200

    fix memory leak around function descriptions
    
    Found by Lsan.
    
    Change-Id: Ia443ed6eb2a20854998a615f3c2bd9fdac156a8c

diff --git a/formula/source/ui/dlg/FormulaHelper.cxx b/formula/source/ui/dlg/FormulaHelper.cxx
index 5805778..6c999bd 100644
--- a/formula/source/ui/dlg/FormulaHelper.cxx
+++ b/formula/source/ui/dlg/FormulaHelper.cxx
@@ -21,6 +21,8 @@
 #include <unotools/charclass.hxx>
 #include <unotools/syslocale.hxx>
 
+#include <boost/scoped_ptr.hpp>
+
 namespace formula
 {
 
@@ -91,7 +93,7 @@ bool FormulaHelper::GetNextFunc( const OUString&  rFormula,
             const sal_uInt32 nCategoryCount = m_pFunctionManager->getCount();
             for(sal_uInt32 j= 0; j < nCategoryCount && !*ppFDesc; ++j)
             {
-                const IFunctionCategory* pCategory = m_pFunctionManager->getCategory(j);
+                boost::scoped_ptr<const IFunctionCategory> pCategory(m_pFunctionManager->getCategory(j));
                 const sal_uInt32 nCount = pCategory->getCount();
                 for(sal_uInt32 i = 0 ; i < nCount; ++i)
                 {
diff --git a/include/formula/IFunctionDescription.hxx b/include/formula/IFunctionDescription.hxx
index a3570bb..579d36b 100644
--- a/include/formula/IFunctionDescription.hxx
+++ b/include/formula/IFunctionDescription.hxx
@@ -60,7 +60,7 @@ namespace formula
         ~IFunctionManager() {}
     };
 
-    class SAL_NO_VTABLE IFunctionCategory
+    class IFunctionCategory
     {
     public:
         IFunctionCategory(){}
@@ -70,8 +70,7 @@ namespace formula
         virtual sal_uInt32                  getNumber() const = 0;
         virtual OUString             getName() const = 0;
 
-    protected:
-        ~IFunctionCategory() {}
+        virtual ~IFunctionCategory() {}
     };
 
     class SAL_NO_VTABLE IFunctionDescription


More information about the Libreoffice-commits mailing list