From 0ffa3abc7d6c0437ece30cfb1430d28ffcc9f5c1 Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Thu, 15 Jan 2015 21:47:44 +0100 Subject: rhbz#1163106: tdoc_ucp: fix life cycle of OfficeDocumentsCloseListener The tdoc_ucp::OfficeDocumentsManager lives until the service manager is disposed on shutdown, but if the database stuff isn't disposed in due time then a document may call the notifyClosing() on the listener after the OfficeDocumentsManager dies; probably something is leaking the ODatabaseContext... Change-Id: I59662b910589d7270697452b2f4ca6c960d22f22 --- ucb/source/ucp/tdoc/tdoc_docmgr.cxx | 9 ++++++--- ucb/source/ucp/tdoc/tdoc_docmgr.hxx | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) (limited to 'ucb') diff --git a/ucb/source/ucp/tdoc/tdoc_docmgr.cxx b/ucb/source/ucp/tdoc/tdoc_docmgr.cxx index f6da87a35421..79e4e2b015b4 100644 --- a/ucb/source/ucp/tdoc/tdoc_docmgr.cxx +++ b/ucb/source/ucp/tdoc/tdoc_docmgr.cxx @@ -74,6 +74,8 @@ void SAL_CALL OfficeDocumentsManager::OfficeDocumentsCloseListener::notifyClosin const lang::EventObject& Source ) throw ( uno::RuntimeException, std::exception ) { + if (!m_pManager) return; // disposed? + document::DocumentEvent aDocEvent; aDocEvent.Source = Source.Source; aDocEvent.EventName = "OfficeDocumentsListener::notifyClosing"; @@ -124,6 +126,7 @@ OfficeDocumentsManager::~OfficeDocumentsManager() // objects are actually released/destroyed upon shutdown is not defined. And when we arrive *here*, // OOo *is* shutting down currently, since we're held by the TDOC provider, which is disposed // upon shutdown. + m_xDocCloseListener->Dispose(); } @@ -235,7 +238,7 @@ void SAL_CALL OfficeDocumentsManager::documentEventOccured( "OnLoadFinished/OnCreate event: got no close broadcaster!" ); if ( xCloseBroadcaster.is() ) - xCloseBroadcaster->addCloseListener( m_xDocCloseListener ); + xCloseBroadcaster->addCloseListener(m_xDocCloseListener.get()); // Propagate document closure. OSL_ENSURE( m_pDocEventListener, @@ -294,7 +297,7 @@ void SAL_CALL OfficeDocumentsManager::documentEventOccured( "OnUnload event: got no XCloseBroadcaster from XModel" ); if ( xCloseBroadcaster.is() ) - xCloseBroadcaster->removeCloseListener( m_xDocCloseListener ); + xCloseBroadcaster->removeCloseListener(m_xDocCloseListener.get()); m_aDocs.erase( it ); } @@ -501,7 +504,7 @@ void OfficeDocumentsManager::buildDocumentsList() "buildDocumentsList: got no close broadcaster!" ); if ( xCloseBroadcaster.is() ) - xCloseBroadcaster->addCloseListener( m_xDocCloseListener ); + xCloseBroadcaster->addCloseListener(m_xDocCloseListener.get()); } } } diff --git a/ucb/source/ucp/tdoc/tdoc_docmgr.hxx b/ucb/source/ucp/tdoc/tdoc_docmgr.hxx index 003e78476995..f71f0c78086e 100644 --- a/ucb/source/ucp/tdoc/tdoc_docmgr.hxx +++ b/ucb/source/ucp/tdoc/tdoc_docmgr.hxx @@ -22,6 +22,7 @@ #include +#include #include "osl/mutex.hxx" #include "cppuhelper/implbase1.hxx" @@ -90,7 +91,7 @@ namespace tdoc_ucp { { public: OfficeDocumentsCloseListener( OfficeDocumentsManager * pMgr ) - : m_pManager( pMgr ) {}; + : m_pManager( pMgr ) {} // util::XCloseListener virtual void SAL_CALL queryClosing( @@ -107,6 +108,9 @@ namespace tdoc_ucp { virtual void SAL_CALL disposing( const com::sun::star::lang::EventObject & Source ) throw ( com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE; + + void Dispose() { m_pManager = 0; } + private: OfficeDocumentsManager * m_pManager; }; @@ -185,8 +189,7 @@ namespace tdoc_ucp { com::sun::star::frame::XModuleManager2 > m_xModuleMgr; DocumentList m_aDocs; OfficeDocumentsEventListener * m_pDocEventListener; - com::sun::star::uno::Reference< - com::sun::star::util::XCloseListener > m_xDocCloseListener; + ::rtl::Reference m_xDocCloseListener; }; } // namespace tdoc_ucp -- cgit