[Libreoffice-commits] core.git: Branch 'libreoffice-4-4' - sw/source

Michael Stahl mstahl at redhat.com
Fri Jan 16 01:13:12 PST 2015


 sw/source/uibase/dbui/dbmgr.cxx |   41 ++++++++++++++++++++++++++--------------
 1 file changed, 27 insertions(+), 14 deletions(-)

New commits:
commit be13badc357b5639b8f76198dc9ff33fa6dabe88
Author: Michael Stahl <mstahl at redhat.com>
Date:   Thu Jan 15 17:00:13 2015 +0100

    rhbz#1175027: sw: fix life cycle of SwConnectionDisposedListener_Impl
    
    The SwDBManager is owned by SwDoc, so if the database thing is still
    alive when SwDoc dies (which may or may not indicate a leak), the
    listener will crash when the database stuff is eventually disposed
    during shutdown.
    
    Change-Id: I2bb5eb35f0a403374bc8f123b85ba2d7244016b0
    (cherry picked from commit 4f747afae591f244164df25d96a83f417e6c0698)
    Reviewed-on: https://gerrit.libreoffice.org/13934
    Tested-by: Caolán McNamara <caolanm at redhat.com>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx
index 5780001..584efa3 100644
--- a/sw/source/uibase/dbui/dbmgr.cxx
+++ b/sw/source/uibase/dbui/dbmgr.cxx
@@ -198,26 +198,35 @@ bool lcl_getCountFromResultSet( sal_Int32& rCount, const uno::Reference<XResultS
 class SwConnectionDisposedListener_Impl : public cppu::WeakImplHelper1
 < lang::XEventListener >
 {
-    SwDBManager&     rDBManager;
+private:
+    SwDBManager * m_pDBManager;
 
     virtual void SAL_CALL disposing( const EventObject& Source ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
+
 public:
     SwConnectionDisposedListener_Impl(SwDBManager& rMgr);
     virtual ~SwConnectionDisposedListener_Impl();
 
+    void Dispose() { m_pDBManager = 0; }
+
 };
 
 struct SwDBManager_Impl
 {
     SwDSParam*          pMergeData;
     AbstractMailMergeDlg*     pMergeDialog;
-    uno::Reference<lang::XEventListener> xDisposeListener;
+    ::rtl::Reference<SwConnectionDisposedListener_Impl> m_xDisposeListener;
 
     SwDBManager_Impl(SwDBManager& rDBManager)
        :pMergeData(0)
        ,pMergeDialog(0)
-       ,xDisposeListener(new SwConnectionDisposedListener_Impl(rDBManager))
+       , m_xDisposeListener(new SwConnectionDisposedListener_Impl(rDBManager))
         {}
+
+    ~SwDBManager_Impl()
+    {
+        m_xDisposeListener->Dispose();
+    }
 };
 
 static void lcl_InitNumberFormatter(SwDSParam& rParam, uno::Reference<XDataSource> xSource)
@@ -350,7 +359,7 @@ bool SwDBManager::MergeNew( const SwMergeDescriptor& rMergeDesc )
             {
                 uno::Reference<XComponent> xComponent(pInsert->xConnection, UNO_QUERY);
                 if(xComponent.is())
-                    xComponent->addEventListener(pImpl->xDisposeListener);
+                    xComponent->addEventListener(pImpl->m_xDisposeListener.get());
             }
             catch(const Exception&)
             {
@@ -2125,7 +2134,7 @@ uno::Reference< XConnection> SwDBManager::RegisterConnection(OUString& rDataSour
         {
             uno::Reference<XComponent> xComponent(pFound->xConnection, UNO_QUERY);
             if(xComponent.is())
-                xComponent->addEventListener(pImpl->xDisposeListener);
+                xComponent->addEventListener(pImpl->m_xDisposeListener.get());
         }
         catch(const Exception&)
         {
@@ -2237,7 +2246,7 @@ SwDSParam* SwDBManager::FindDSData(const SwDBData& rData, bool bCreate)
             {
                 uno::Reference<XComponent> xComponent(pFound->xConnection, UNO_QUERY);
                 if(xComponent.is())
-                    xComponent->addEventListener(pImpl->xDisposeListener);
+                    xComponent->addEventListener(pImpl->m_xDisposeListener.get());
             }
             catch(const Exception&)
             {
@@ -2274,7 +2283,7 @@ SwDSParam*  SwDBManager::FindDSConnection(const OUString& rDataSource, bool bCre
         {
             uno::Reference<XComponent> xComponent(pFound->xConnection, UNO_QUERY);
             if(xComponent.is())
-                xComponent->addEventListener(pImpl->xDisposeListener);
+                xComponent->addEventListener(pImpl->m_xDisposeListener.get());
         }
         catch(const Exception&)
         {
@@ -2823,27 +2832,31 @@ uno::Reference<XResultSet> SwDBManager::createCursor(const OUString& _sDataSourc
     return xResultSet;
 }
 
-SwConnectionDisposedListener_Impl::SwConnectionDisposedListener_Impl(SwDBManager& rMgr) :
-    rDBManager(rMgr)
+SwConnectionDisposedListener_Impl::SwConnectionDisposedListener_Impl(SwDBManager& rManager)
+    : m_pDBManager(&rManager)
 {
-};
+}
 
 SwConnectionDisposedListener_Impl::~SwConnectionDisposedListener_Impl()
 {
-};
+}
 
 void SwConnectionDisposedListener_Impl::disposing( const EventObject& rSource )
         throw (RuntimeException, std::exception)
 {
     ::SolarMutexGuard aGuard;
+
+    if (!m_pDBManager) return; // we're disposed too!
+
     uno::Reference<XConnection> xSource(rSource.Source, UNO_QUERY);
-    for(sal_uInt16 nPos = rDBManager.aDataSourceParams.size(); nPos; nPos--)
+    for (size_t nPos = m_pDBManager->aDataSourceParams.size(); nPos; nPos--)
     {
-        SwDSParam* pParam = &rDBManager.aDataSourceParams[nPos - 1];
+        SwDSParam* pParam = &m_pDBManager->aDataSourceParams[nPos - 1];
         if(pParam->xConnection.is() &&
                 (xSource == pParam->xConnection))
         {
-            rDBManager.aDataSourceParams.erase(rDBManager.aDataSourceParams.begin() + nPos - 1);
+            m_pDBManager->aDataSourceParams.erase(
+                    m_pDBManager->aDataSourceParams.begin() + nPos - 1);
         }
     }
 }


More information about the Libreoffice-commits mailing list