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

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Mon May 17 08:40:03 UTC 2021


 chart2/source/controller/main/CommandDispatch.cxx |   29 ++++++----------------
 chart2/source/controller/main/CommandDispatch.hxx |    3 +-
 2 files changed, 11 insertions(+), 21 deletions(-)

New commits:
commit dd5666a0425935f2389811abf750f435411e3fe0
Author:     Noel Grandin <noelgrandin at gmail.com>
AuthorDate: Sun May 16 21:34:35 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Mon May 17 10:39:20 2021 +0200

    fix leak in CommandDispatch
    
    Change-Id: I0249b18fd40f4f5ef95e2101286dc25782c42eb5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115684
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/chart2/source/controller/main/CommandDispatch.cxx b/chart2/source/controller/main/CommandDispatch.cxx
index 22e0a52c204f..ed6370a5228b 100644
--- a/chart2/source/controller/main/CommandDispatch.cxx
+++ b/chart2/source/controller/main/CommandDispatch.cxx
@@ -26,25 +26,6 @@ using namespace ::com::sun::star;
 using ::com::sun::star::uno::Reference;
 using ::com::sun::star::uno::Sequence;
 
-namespace
-{
-template< class Map >
-    void lcl_DisposeAndClearAndDeleteAllMapElements(
-        Map & rMap,
-        const Reference< uno::XInterface > & xEventSource )
-{
-    for( const auto& rElement : rMap )
-    {
-        if( rElement.second )
-        {
-            rElement.second->disposeAndClear( xEventSource );
-            delete rElement.second;
-        }
-    }
-}
-
-} // anonymous namespace
-
 namespace chart
 {
 
@@ -65,7 +46,15 @@ void CommandDispatch::initialize()
 /// is called when this is disposed
 void SAL_CALL CommandDispatch::disposing()
 {
-    lcl_DisposeAndClearAndDeleteAllMapElements( m_aListeners, static_cast< cppu::OWeakObject* >( this ));
+    Reference< uno::XInterface > xEventSource(static_cast< cppu::OWeakObject* >( this ));
+    for( auto& rElement : m_aListeners )
+    {
+        if( rElement.second )
+        {
+            rElement.second->disposeAndClear( xEventSource );
+            rElement.second.reset();
+        }
+    }
     m_aListeners.clear();
 }
 
diff --git a/chart2/source/controller/main/CommandDispatch.hxx b/chart2/source/controller/main/CommandDispatch.hxx
index 1c7295186038..37de7c59c119 100644
--- a/chart2/source/controller/main/CommandDispatch.hxx
+++ b/chart2/source/controller/main/CommandDispatch.hxx
@@ -25,6 +25,7 @@
 #include <com/sun/star/util/XModifyListener.hpp>
 
 #include <map>
+#include <memory>
 
 namespace com::sun::star::uno { class XComponentContext; }
 namespace com::sun::star::util { class XURLTransformer; }
@@ -120,7 +121,7 @@ private:
     css::uno::Reference< css::uno::XComponentContext > m_xContext;
     css::uno::Reference< css::util::XURLTransformer >  m_xURLTransformer;
 
-    typedef std::map< OUString, ::comphelper::OInterfaceContainerHelper2* >
+    typedef std::map< OUString, std::unique_ptr<::comphelper::OInterfaceContainerHelper2> >
         tListenerMap;
 
     tListenerMap m_aListeners;


More information about the Libreoffice-commits mailing list