1 |
tv |
812201 |
From 4f747afae591f244164df25d96a83f417e6c0698 Mon Sep 17 00:00:00 2001 |
2 |
|
|
From: Michael Stahl <mstahl@redhat.com> |
3 |
|
|
Date: Thu, 15 Jan 2015 17:00:13 +0100 |
4 |
|
|
Subject: [PATCH] rhbz#1175027: sw: fix life cycle of |
5 |
|
|
SwConnectionDisposedListener_Impl |
6 |
|
|
|
7 |
|
|
The SwDBManager is owned by SwDoc, so if the database thing is still |
8 |
|
|
alive when SwDoc dies (which may or may not indicate a leak), the |
9 |
|
|
listener will crash when the database stuff is eventually disposed |
10 |
|
|
during shutdown. |
11 |
|
|
|
12 |
|
|
Change-Id: I2bb5eb35f0a403374bc8f123b85ba2d7244016b0 |
13 |
|
|
--- |
14 |
|
|
sw/source/uibase/dbui/dbmgr.cxx | 41 +++++++++++++++++++++++++++-------------- |
15 |
|
|
1 file changed, 27 insertions(+), 14 deletions(-) |
16 |
|
|
|
17 |
|
|
diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx |
18 |
|
|
index ddcaf6e..fc79e80 100644 |
19 |
|
|
--- a/sw/source/uibase/dbui/dbmgr.cxx |
20 |
|
|
+++ b/sw/source/uibase/dbui/dbmgr.cxx |
21 |
|
|
@@ -198,26 +198,35 @@ bool lcl_getCountFromResultSet( sal_Int32& rCount, const uno::Reference<XResultS |
22 |
|
|
class SwConnectionDisposedListener_Impl : public cppu::WeakImplHelper1 |
23 |
|
|
< lang::XEventListener > |
24 |
|
|
{ |
25 |
|
|
- SwDBManager& rDBManager; |
26 |
|
|
+private: |
27 |
|
|
+ SwDBManager * m_pDBManager; |
28 |
|
|
|
29 |
|
|
virtual void SAL_CALL disposing( const EventObject& Source ) throw (RuntimeException, std::exception) SAL_OVERRIDE; |
30 |
|
|
+ |
31 |
|
|
public: |
32 |
|
|
SwConnectionDisposedListener_Impl(SwDBManager& rMgr); |
33 |
|
|
virtual ~SwConnectionDisposedListener_Impl(); |
34 |
|
|
|
35 |
|
|
+ void Dispose() { m_pDBManager = 0; } |
36 |
|
|
+ |
37 |
|
|
}; |
38 |
|
|
|
39 |
|
|
struct SwDBManager_Impl |
40 |
|
|
{ |
41 |
|
|
SwDSParam* pMergeData; |
42 |
|
|
AbstractMailMergeDlg* pMergeDialog; |
43 |
|
|
- uno::Reference<lang::XEventListener> xDisposeListener; |
44 |
|
|
+ ::rtl::Reference<SwConnectionDisposedListener_Impl> m_xDisposeListener; |
45 |
|
|
|
46 |
|
|
SwDBManager_Impl(SwDBManager& rDBManager) |
47 |
|
|
:pMergeData(0) |
48 |
|
|
,pMergeDialog(0) |
49 |
|
|
- ,xDisposeListener(new SwConnectionDisposedListener_Impl(rDBManager)) |
50 |
|
|
+ , m_xDisposeListener(new SwConnectionDisposedListener_Impl(rDBManager)) |
51 |
|
|
{} |
52 |
|
|
+ |
53 |
|
|
+ ~SwDBManager_Impl() |
54 |
|
|
+ { |
55 |
|
|
+ m_xDisposeListener->Dispose(); |
56 |
|
|
+ } |
57 |
|
|
}; |
58 |
|
|
|
59 |
|
|
static void lcl_InitNumberFormatter(SwDSParam& rParam, uno::Reference<XDataSource> xSource) |
60 |
|
|
@@ -350,7 +359,7 @@ bool SwDBManager::MergeNew( const SwMergeDescriptor& rMergeDesc ) |
61 |
|
|
{ |
62 |
|
|
uno::Reference<XComponent> xComponent(pInsert->xConnection, UNO_QUERY); |
63 |
|
|
if(xComponent.is()) |
64 |
|
|
- xComponent->addEventListener(pImpl->xDisposeListener); |
65 |
|
|
+ xComponent->addEventListener(pImpl->m_xDisposeListener.get()); |
66 |
|
|
} |
67 |
|
|
catch(const Exception&) |
68 |
|
|
{ |
69 |
|
|
@@ -2124,7 +2133,7 @@ uno::Reference< XConnection> SwDBManager::RegisterConnection(OUString& rDataSour |
70 |
|
|
{ |
71 |
|
|
uno::Reference<XComponent> xComponent(pFound->xConnection, UNO_QUERY); |
72 |
|
|
if(xComponent.is()) |
73 |
|
|
- xComponent->addEventListener(pImpl->xDisposeListener); |
74 |
|
|
+ xComponent->addEventListener(pImpl->m_xDisposeListener.get()); |
75 |
|
|
} |
76 |
|
|
catch(const Exception&) |
77 |
|
|
{ |
78 |
|
|
@@ -2236,7 +2245,7 @@ SwDSParam* SwDBManager::FindDSData(const SwDBData& rData, bool bCreate) |
79 |
|
|
{ |
80 |
|
|
uno::Reference<XComponent> xComponent(pFound->xConnection, UNO_QUERY); |
81 |
|
|
if(xComponent.is()) |
82 |
|
|
- xComponent->addEventListener(pImpl->xDisposeListener); |
83 |
|
|
+ xComponent->addEventListener(pImpl->m_xDisposeListener.get()); |
84 |
|
|
} |
85 |
|
|
catch(const Exception&) |
86 |
|
|
{ |
87 |
|
|
@@ -2273,7 +2282,7 @@ SwDSParam* SwDBManager::FindDSConnection(const OUString& rDataSource, bool bCre |
88 |
|
|
{ |
89 |
|
|
uno::Reference<XComponent> xComponent(pFound->xConnection, UNO_QUERY); |
90 |
|
|
if(xComponent.is()) |
91 |
|
|
- xComponent->addEventListener(pImpl->xDisposeListener); |
92 |
|
|
+ xComponent->addEventListener(pImpl->m_xDisposeListener.get()); |
93 |
|
|
} |
94 |
|
|
catch(const Exception&) |
95 |
|
|
{ |
96 |
|
|
@@ -2822,27 +2831,31 @@ uno::Reference<XResultSet> SwDBManager::createCursor(const OUString& _sDataSourc |
97 |
|
|
return xResultSet; |
98 |
|
|
} |
99 |
|
|
|
100 |
|
|
-SwConnectionDisposedListener_Impl::SwConnectionDisposedListener_Impl(SwDBManager& rMgr) : |
101 |
|
|
- rDBManager(rMgr) |
102 |
|
|
+SwConnectionDisposedListener_Impl::SwConnectionDisposedListener_Impl(SwDBManager& rManager) |
103 |
|
|
+ : m_pDBManager(&rManager) |
104 |
|
|
{ |
105 |
|
|
-}; |
106 |
|
|
+} |
107 |
|
|
|
108 |
|
|
SwConnectionDisposedListener_Impl::~SwConnectionDisposedListener_Impl() |
109 |
|
|
{ |
110 |
|
|
-}; |
111 |
|
|
+} |
112 |
|
|
|
113 |
|
|
void SwConnectionDisposedListener_Impl::disposing( const EventObject& rSource ) |
114 |
|
|
throw (RuntimeException, std::exception) |
115 |
|
|
{ |
116 |
|
|
::SolarMutexGuard aGuard; |
117 |
|
|
+ |
118 |
|
|
+ if (!m_pDBManager) return; // we're disposed too! |
119 |
|
|
+ |
120 |
|
|
uno::Reference<XConnection> xSource(rSource.Source, UNO_QUERY); |
121 |
|
|
- for(sal_uInt16 nPos = rDBManager.aDataSourceParams.size(); nPos; nPos--) |
122 |
|
|
+ for (size_t nPos = m_pDBManager->aDataSourceParams.size(); nPos; nPos--) |
123 |
|
|
{ |
124 |
|
|
- SwDSParam* pParam = &rDBManager.aDataSourceParams[nPos - 1]; |
125 |
|
|
+ SwDSParam* pParam = &m_pDBManager->aDataSourceParams[nPos - 1]; |
126 |
|
|
if(pParam->xConnection.is() && |
127 |
|
|
(xSource == pParam->xConnection)) |
128 |
|
|
{ |
129 |
|
|
- rDBManager.aDataSourceParams.erase(rDBManager.aDataSourceParams.begin() + nPos - 1); |
130 |
|
|
+ m_pDBManager->aDataSourceParams.erase( |
131 |
|
|
+ m_pDBManager->aDataSourceParams.begin() + nPos - 1); |
132 |
|
|
} |
133 |
|
|
} |
134 |
|
|
} |
135 |
|
|
-- |
136 |
|
|
2.1.0 |
137 |
|
|
|