Resolves: rhbz#1175027 fix life cycle of SwConnectionDisposedListener_Impl

f41
David Tardon 10 years ago
parent 8f43e1e912
commit 4f43b0fc00

@ -0,0 +1,137 @@
From 4f747afae591f244164df25d96a83f417e6c0698 Mon Sep 17 00:00:00 2001
From: Michael Stahl <mstahl@redhat.com>
Date: Thu, 15 Jan 2015 17:00:13 +0100
Subject: [PATCH] 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
---
sw/source/uibase/dbui/dbmgr.cxx | 41 +++++++++++++++++++++++++++--------------
1 file changed, 27 insertions(+), 14 deletions(-)
diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx
index ddcaf6e..fc79e80 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);
}
}
}
--
2.1.0

@ -328,6 +328,7 @@ Patch20: 0001-classic-draw-rectangles-fit-to-contour-utterly-broke.patch
Patch21: 0001-Use-the-same-advanced-Ellipse-and-Rectangle-shapes-i.patch
Patch22: 0001-rhbz-1180114-writerfilter-don-t-crash-on-w-customXml.patch
Patch23: 0001-if-we-change-the-keys-we-have-to-resort-based-on-the.patch
Patch24: 0001-rhbz-1175027-sw-fix-life-cycle-of-SwConnectionDispos.patch
%define instdir %{_libdir}
%define baseinstdir %{instdir}/libreoffice
@ -2351,9 +2352,10 @@ update-desktop-database %{_datadir}/applications &> /dev/null || :
%endif
%changelog
* Thu Jan 15 2015 David Tardon <dtardon@redhat.com> - 1:4.4.0.2-2
* Mon Jan 19 2015 David Tardon <dtardon@redhat.com> - 1:4.4.0.2-2
- Resolves: rhbz#1180114 writerfilter: don't crash on w:customXmlDelRangeStart
etc.
- Resolves: rhbz#1175027 fix life cycle of SwConnectionDisposedListener_Impl
* Fri Jan 09 2015 David Tardon <dtardon@redhat.com> - 1:4.4.0.2-1
- update to 4.4.0 rc2

Loading…
Cancel
Save