[Libreoffice-commits] core.git: desktop/source scripting/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Mon Nov 5 19:08:01 UTC 2018


 desktop/source/app/app.cxx           |    7 -------
 scripting/source/basprov/basprov.cxx |   15 +++++++++++++++
 scripting/source/basprov/basprov.hxx |    7 ++++++-
 3 files changed, 21 insertions(+), 8 deletions(-)

New commits:
commit ba796f2cddb8e63e1ec99e5c32b71d86fdf8e7d6
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Sat Nov 3 16:48:49 2018 +0300
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Mon Nov 5 20:06:58 2018 +0100

    tdf#121143: don't send OnCloseApp twice; properly cleanup AppBasicManager
    
    The OnCloseApp event is being sent twice: first time in
    SfxTerminateListener_Impl::notifyTermination (in Desktop::terminate),
    and the second time in Desktop::doShutdown. The second event happens
    after application's Basic manager already was destroyed in
    SfxApplication::Deinitialize. The Basic provider, which holds a pointer
    to the manager, doesn't properly cleanup upon the manager's destruction,
    thus trying to use it after free.
    
    This removes the second (duplicate) generated OnCloseApp event, and
    makes BasicProviderImpl inherit from SfxListener to allow receiving the
    manager's SfxHintId::Dying notification.
    
    Change-Id: Iabf1432c41b1925b11b5a89e5fd8a6ae8249831e
    Reviewed-on: https://gerrit.libreoffice.org/62810
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/desktop/source/app/app.cxx b/desktop/source/app/app.cxx
index 0cc6c649e7e1..fa8204304f53 100644
--- a/desktop/source/app/app.cxx
+++ b/desktop/source/app/app.cxx
@@ -1686,13 +1686,6 @@ int Desktop::doShutdown()
     if ( pExecGlobals->bRestartRequested )
         SetRestartState();
 
-    if (pExecGlobals->xGlobalBroadcaster.is())
-    {
-        css::document::DocumentEvent aEvent;
-        aEvent.EventName = "OnCloseApp";
-        pExecGlobals->xGlobalBroadcaster->documentEventOccured(aEvent);
-    }
-
     // Restore old value
     const CommandLineArgs& rCmdLineArgs = GetCommandLineArgs();
     if ( rCmdLineArgs.IsHeadless() || rCmdLineArgs.IsEventTesting() )
diff --git a/scripting/source/basprov/basprov.cxx b/scripting/source/basprov/basprov.cxx
index f1805c36a16e..6c856d5a5a24 100644
--- a/scripting/source/basprov/basprov.cxx
+++ b/scripting/source/basprov/basprov.cxx
@@ -158,6 +158,17 @@ namespace basprov
         return bIsShared;
     }
 
+    // SfxListener
+    void BasicProviderImpl::Notify(SfxBroadcaster& rBC, const SfxHint& rHint)
+    {
+        if (auto pManager = dynamic_cast<const BasicManager*>(&rBC))
+            if (pManager == m_pAppBasicManager && rHint.GetId() == SfxHintId::Dying)
+            {
+                EndListening(*m_pAppBasicManager);
+                m_pAppBasicManager = nullptr;
+            }
+    }
+
     // XServiceInfo
     OUString BasicProviderImpl::getImplementationName(  )
     {
@@ -258,7 +269,11 @@ namespace basprov
 
         // TODO
         if ( !m_pAppBasicManager )
+        {
             m_pAppBasicManager = SfxApplication::GetBasicManager();
+            if (m_pAppBasicManager)
+                StartListening(*m_pAppBasicManager);
+        }
 
         if ( !m_xLibContainerApp.is() )
             m_xLibContainerApp.set( SfxGetpApp()->GetBasicContainer(), UNO_QUERY );
diff --git a/scripting/source/basprov/basprov.hxx b/scripting/source/basprov/basprov.hxx
index b3ba2617982c..d10f10e7e970 100644
--- a/scripting/source/basprov/basprov.hxx
+++ b/scripting/source/basprov/basprov.hxx
@@ -29,6 +29,7 @@
 #include <com/sun/star/document/XScriptInvocationContext.hpp>
 #include <com/sun/star/uno/XComponentContext.hpp>
 #include <cppuhelper/implbase.hxx>
+#include <svl/lstner.hxx>
 
 class BasicManager;
 
@@ -47,7 +48,7 @@ namespace basprov
         css::script::browse::XBrowseNode > BasicProviderImpl_BASE;
 
 
-    class BasicProviderImpl : public BasicProviderImpl_BASE
+    class BasicProviderImpl : public BasicProviderImpl_BASE, public SfxListener
     {
     private:
         BasicManager*   m_pAppBasicManager;
@@ -86,6 +87,10 @@ namespace basprov
         virtual css::uno::Sequence< css::uno::Reference< css::script::browse::XBrowseNode > > SAL_CALL getChildNodes(  ) override;
         virtual sal_Bool SAL_CALL hasChildNodes(  ) override;
         virtual sal_Int16 SAL_CALL getType(  ) override;
+
+    protected:
+        // SfxListener
+        virtual void Notify(SfxBroadcaster& rBC, const SfxHint& rHint) override;
     };
 
 


More information about the Libreoffice-commits mailing list