diff options
author | Daniel Boelzle <dbo@openoffice.org> | 2000-12-06 15:48:11 +0000 |
---|---|---|
committer | Daniel Boelzle <dbo@openoffice.org> | 2000-12-06 15:48:11 +0000 |
commit | 83804de064511dd3fcb6ebb559f691e860392bfc (patch) | |
tree | c02d4de2343da9f33eb10d005a146b006703770c /cppuhelper | |
parent | e73d5c871e382846e65f2093a907eac41ef8ed4d (diff) |
#80866# fix for weakref mem leak
Diffstat (limited to 'cppuhelper')
-rw-r--r-- | cppuhelper/source/weak.cxx | 57 |
1 files changed, 36 insertions, 21 deletions
diff --git a/cppuhelper/source/weak.cxx b/cppuhelper/source/weak.cxx index 3765fc5e7852..c2cc7a0faa0a 100644 --- a/cppuhelper/source/weak.cxx +++ b/cppuhelper/source/weak.cxx @@ -2,9 +2,9 @@ * * $RCSfile: weak.cxx,v $ * - * $Revision: 1.1.1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: hr $ $Date: 2000-09-18 15:26:10 $ + * last change: $Author: dbo $ $Date: 2000-12-06 16:48:11 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -456,47 +456,62 @@ void SAL_CALL OWeakRefListener::dispose() //-- WeakReferenceHelper ---------------------------------------------------------- //------------------------------------------------------------------------ WeakReferenceHelper::WeakReferenceHelper(const Reference< XInterface >& xInt) + : m_pImpl( 0 ) { - m_pImpl = new OWeakRefListener(xInt); - m_pImpl->acquire(); + if (xInt.is()) + { + m_pImpl = new OWeakRefListener(xInt); + m_pImpl->acquire(); + } } WeakReferenceHelper::WeakReferenceHelper(const WeakReferenceHelper& rWeakRef) + : m_pImpl( 0 ) { - m_pImpl = rWeakRef.m_pImpl; - - if( m_pImpl ) + Reference< XInterface > xInt( rWeakRef.get() ); + if (xInt.is()) + { + m_pImpl = new OWeakRefListener(xInt); m_pImpl->acquire(); + } } WeakReferenceHelper& WeakReferenceHelper::operator=(const WeakReferenceHelper& rWeakRef) { - OWeakRefListener* pOldImpl; + if (this != &rWeakRef) { - // the weak reference is multithread save - MutexGuard guard(cppu::getWeakMutex()); - if (m_pImpl == rWeakRef.m_pImpl) - return *this; - - pOldImpl = m_pImpl; - - m_pImpl = rWeakRef.m_pImpl; - if ( m_pImpl ) + Reference< XInterface > xInt( rWeakRef.get() ); + if (m_pImpl) + { + if (m_pImpl->m_XWeakConnectionPoint.is()) + { + m_pImpl->m_XWeakConnectionPoint->removeReference((XReference*)m_pImpl); + m_pImpl->m_XWeakConnectionPoint.clear(); + } + m_pImpl->release(); + m_pImpl = 0; + } + if (xInt.is()) { + m_pImpl = new OWeakRefListener(xInt); m_pImpl->acquire(); } } - - // maybe call the destructor. It is better to release the guard before this call. - if( pOldImpl ) - pOldImpl->release(); return *this; } WeakReferenceHelper::~WeakReferenceHelper() { if (m_pImpl) + { + if (m_pImpl->m_XWeakConnectionPoint.is()) + { + m_pImpl->m_XWeakConnectionPoint->removeReference((XReference*)m_pImpl); + m_pImpl->m_XWeakConnectionPoint.clear(); + } m_pImpl->release(); + m_pImpl = 0; // for safety + } } Reference< XInterface > WeakReferenceHelper::get() const |