diff options
author | Michael Stahl <mstahl@redhat.com> | 2015-01-15 17:00:13 +0100 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2015-01-15 17:09:11 +0100 |
commit | 4f747afae591f244164df25d96a83f417e6c0698 (patch) | |
tree | ba6ec57d451df600df6c111d19e29137fd9b78e6 /sw/source | |
parent | 231e74be5ed724a18cc5867212270e46a8fda9bc (diff) |
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
Diffstat (limited to 'sw/source')
-rw-r--r-- | sw/source/uibase/dbui/dbmgr.cxx | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx index ddcaf6e37314..fc79e8054b52 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&) { @@ -2124,7 +2133,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&) { @@ -2236,7 +2245,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&) { @@ -2273,7 +2282,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&) { @@ -2822,27 +2831,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); } } } |