From 900bc2c56ae5ba21edafccccfd68619e1006b79b Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Wed, 6 Apr 2011 13:43:46 +0100 Subject: fix ownership cycle and leak --- sfx2/source/bastyp/fltfnc.cxx | 8 +++++++- sfx2/source/bastyp/fltlst.cxx | 36 +++++++++++++++++++++++++++++++++++- sfx2/source/bastyp/fltlst.hxx | 15 +++++---------- 3 files changed, 47 insertions(+), 12 deletions(-) (limited to 'sfx2') diff --git a/sfx2/source/bastyp/fltfnc.cxx b/sfx2/source/bastyp/fltfnc.cxx index 533320e64acd..36b812d24f76 100644 --- a/sfx2/source/bastyp/fltfnc.cxx +++ b/sfx2/source/bastyp/fltfnc.cxx @@ -92,6 +92,7 @@ #include #include +#include using namespace ::com::sun::star::uno; using namespace ::com::sun::star::ucb; @@ -122,13 +123,18 @@ using namespace ::com::sun::star::beans; #include #include +namespace +{ + class theSfxFilterListener : public rtl::Static {}; +} + static SfxFilterList_Impl* pFilterArr = 0; static sal_Bool bFirstRead = sal_True; static void CreateFilterArr() { pFilterArr = new SfxFilterList_Impl; - new SfxFilterListener(); + theSfxFilterListener::get(); } //---------------------------------------------------------------- diff --git a/sfx2/source/bastyp/fltlst.cxx b/sfx2/source/bastyp/fltlst.cxx index 3fc966c45d8e..16f1ccf64d20 100644 --- a/sfx2/source/bastyp/fltlst.cxx +++ b/sfx2/source/bastyp/fltlst.cxx @@ -49,6 +49,39 @@ //***************************************************************************************************************** using namespace ::com::sun::star; + +class SfxRefreshListener : public ::cppu::WeakImplHelper1 +{ + private: + SfxFilterListener *m_pOwner; + + public: + SfxRefreshListener(SfxFilterListener *pOwner) + : m_pOwner(pOwner) + { + } + + virtual ~SfxRefreshListener() + { + } + + // util.XRefreshListener + virtual void SAL_CALL refreshed( const ::com::sun::star::lang::EventObject& rEvent ) + throw(com::sun::star::uno::RuntimeException) + { + m_pOwner->refreshed(rEvent); + } + + // lang.XEventListener + virtual void SAL_CALL disposing(const com::sun::star::lang::EventObject& rEvent) + throw(com::sun::star::uno::RuntimeException) + { + m_pOwner->disposing(rEvent); + } +}; + + + //***************************************************************************************************************** // definitions //***************************************************************************************************************** @@ -85,7 +118,8 @@ SfxFilterListener::SfxFilterListener() if( xNotifier.is() == sal_True ) { m_xFilterCache = xNotifier; - m_xFilterCache->addRefreshListener( this ); + m_xFilterCacheListener = new SfxRefreshListener(this); + m_xFilterCache->addRefreshListener( m_xFilterCacheListener ); } } } diff --git a/sfx2/source/bastyp/fltlst.hxx b/sfx2/source/bastyp/fltlst.hxx index 02af4663037c..e7d010bbbcd7 100644 --- a/sfx2/source/bastyp/fltlst.hxx +++ b/sfx2/source/bastyp/fltlst.hxx @@ -42,28 +42,23 @@ #include #include -//***************************************************************************************************************** -// declarations -//***************************************************************************************************************** -class SfxFilterListener : public ::cppu::WeakImplHelper1< ::com::sun::star::util::XRefreshListener > +class SfxFilterListener { - // member private: ::com::sun::star::uno::Reference< ::com::sun::star::util::XRefreshable > m_xFilterCache; + ::com::sun::star::uno::Reference< ::com::sun::star::util::XRefreshListener > m_xFilterCacheListener; - // c++ interface public: - SfxFilterListener(); - ~SfxFilterListener(); + SfxFilterListener(); + ~SfxFilterListener(); - // uno interface public: // XRefreshListener virtual void SAL_CALL refreshed( const ::com::sun::star::lang::EventObject& aSource ) throw( ::com::sun::star::uno::RuntimeException ); // XEventListener virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& aSource ) throw( ::com::sun::star::uno::RuntimeException ); -}; // SfxFilterListener +}; #endif // _SFX_FLTLST_HXX -- cgit