From 71a7ba716e85cf36a9a4744a6371a18481fe0ff8 Mon Sep 17 00:00:00 2001 From: sb Date: Fri, 2 Jul 2010 15:53:28 +0200 Subject: sb126: #i112784# do not leak ContextAdmin (patch by cmc) --- bridges/source/remote/context/context.cxx | 41 +++++++++---------------------- 1 file changed, 11 insertions(+), 30 deletions(-) (limited to 'bridges') diff --git a/bridges/source/remote/context/context.cxx b/bridges/source/remote/context/context.cxx index edf0eed6d8fd..7a2f3e6e6f66 100644 --- a/bridges/source/remote/context/context.cxx +++ b/bridges/source/remote/context/context.cxx @@ -38,6 +38,7 @@ #include #include "rtl/ustring.hxx" +#include "rtl/instance.hxx" #include #include @@ -109,17 +110,9 @@ ContextMap; static MyCounter thisCounter( "DEBUG : Context" ); #endif -class ContextAdmin; - -ContextAdmin *g_pTheContext = 0; - - - class ContextAdmin { public: - static ContextAdmin *getInstance(); - // listener administration void addContextListener( remote_contextListenerFunc listener , void *pObject ); void removeContextListener( remote_contextListenerFunc listener , void *pObject ); @@ -138,7 +131,7 @@ public: void revokeContext( uno_Context *pRemoteContext ); - uno_Context *get( rtl_uString *pHost ); + uno_Context *getContext( rtl_uString *pHost ); rtl_uString ** getConnectionList( sal_Int32 *pnStringCount, MemAlloc memAlloc ); @@ -152,19 +145,6 @@ private: List m_lstListener; }; -ContextAdmin *ContextAdmin::getInstance() -{ - if( ! g_pTheContext ) { - ::osl::MutexGuard guard( ::osl::Mutex::getGlobalMutex() ); - if( ! g_pTheContext ) { - //TODO This memory is leaked; see #i63473# for when this should be - // changed again: - g_pTheContext = new ContextAdmin; - } - } - return g_pTheContext; -} - void ContextAdmin::addContextListener( remote_contextListenerFunc listener , void *pObject ) { ::osl::MutexGuard guard( m_mutex ); @@ -209,7 +189,7 @@ uno_Context *ContextAdmin::createAndRegisterContext( remote_Connection *pConnect { ::osl::MutexGuard guard( m_mutex ); - uno_Context *pContext = get( pIdStr ); + uno_Context *pContext = getContext( pIdStr ); if( pContext ) { pContext->release( pContext ); @@ -245,7 +225,7 @@ void ContextAdmin::revokeContext( uno_Context *pRemoteContext ) } -uno_Context *ContextAdmin::get( rtl_uString *pHost ) +uno_Context *ContextAdmin::getContext( rtl_uString *pHost ) { ::osl::MutexGuard guard( m_mutex ); @@ -287,6 +267,7 @@ rtl_uString ** ContextAdmin::getConnectionList( } +struct theContextAdmin : public rtl::Static {}; /***************************** * remote_ContextImpl implementation @@ -383,7 +364,7 @@ void remote_ContextImpl::thisDispose( remote_Context *pRemoteC ) if( ! pImpl->m_bDisposed ) { pImpl->m_bDisposed = sal_True; - ContextAdmin::getInstance()->revokeContext( (uno_Context * ) pRemoteC ); + theContextAdmin::get().revokeContext( (uno_Context * ) pRemoteC ); if( pImpl->m_pInstanceProvider ) { @@ -460,7 +441,7 @@ using namespace remote_context; extern "C" remote_Context * SAL_CALL remote_getContext( rtl_uString *pIdString ) { - return (remote_Context *) ContextAdmin::getInstance()->get( pIdString ); + return (remote_Context *) theContextAdmin::get().getContext(pIdString); } @@ -473,7 +454,7 @@ remote_createContext( remote_Connection *pConnection, remote_InstanceProvider *pProvider ) { remote_ContextImpl *p = (remote_ContextImpl * ) - ContextAdmin::getInstance()->createAndRegisterContext( + theContextAdmin::get().createAndRegisterContext( pConnection , pIdStr , pDescription, @@ -487,17 +468,17 @@ remote_createContext( remote_Connection *pConnection, extern "C" void SAL_CALL remote_addContextListener( remote_contextListenerFunc listener, void *pObject ) { - ContextAdmin::getInstance()->addContextListener( listener , pObject ); + theContextAdmin::get().addContextListener( listener , pObject ); } extern "C" void SAL_CALL remote_removeContextListener( remote_contextListenerFunc listener , void *pObject ) { - ContextAdmin::getInstance()->removeContextListener( listener , pObject ); + theContextAdmin::get().removeContextListener( listener , pObject ); } extern "C" rtl_uString ** SAL_CALL remote_getContextList( sal_Int32 *pnStringCount, MemAlloc memAlloc ) { - return ContextAdmin::getInstance()->getConnectionList( pnStringCount , memAlloc ); + return theContextAdmin::get().getConnectionList( pnStringCount , memAlloc ); } -- cgit