INTEGRATION: CWS rpt23fix02 (1.30.10); FILE MERGED

2007/07/30 10:45:47 jsc 1.30.10.1: #i80111# reviewed and applied patch which solved a memeory leak
This commit is contained in:
Jens-Heiner Rechtien
2007-08-03 09:16:02 +00:00
parent 6ba190ab7b
commit 22c0b48404

View File

@@ -4,9 +4,9 @@
* *
* $RCSfile: component_context.cxx,v $ * $RCSfile: component_context.cxx,v $
* *
* $Revision: 1.31 $ * $Revision: 1.32 $
* *
* last change: $Author: obo $ $Date: 2007-07-18 12:17:07 $ * last change: $Author: hr $ $Date: 2007-08-03 10:16:02 $
* *
* The Contents of this file are made available subject to * The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1. * the terms of GNU Lesser General Public License Version 2.1.
@@ -370,7 +370,7 @@ protected:
, lateInit( lateInit_ ) , lateInit( lateInit_ )
{} {}
}; };
typedef ::std::hash_map< OUString, ContextEntry *, OUStringHash > t_map; typedef ::std::hash_map< OUString, ContextEntry * , OUStringHash > t_map;
t_map m_map; t_map m_map;
Reference< lang::XMultiComponentFactory > m_xSMgr; Reference< lang::XMultiComponentFactory > m_xSMgr;
@@ -426,7 +426,7 @@ void ComponentContext::insertByName(
throw (lang::IllegalArgumentException, container::ElementExistException, throw (lang::IllegalArgumentException, container::ElementExistException,
lang::WrappedTargetException, RuntimeException) lang::WrappedTargetException, RuntimeException)
{ {
::std::auto_ptr<ContextEntry> entry( t_map::mapped_type entry(
new ContextEntry( new ContextEntry(
element, element,
/* lateInit_: */ /* lateInit_: */
@@ -434,12 +434,11 @@ void ComponentContext::insertByName(
!element.hasValue() ) ); !element.hasValue() ) );
MutexGuard guard( m_mutex ); MutexGuard guard( m_mutex );
::std::pair<t_map::iterator, bool> insertion( m_map.insert( ::std::pair<t_map::iterator, bool> insertion( m_map.insert(
t_map::value_type( name, entry.get() ) ) ); t_map::value_type( name, entry ) ) );
if (! insertion.second) if (! insertion.second)
throw container::ElementExistException( throw container::ElementExistException(
OUSTR("element already exists: ") + name, OUSTR("element already exists: ") + name,
static_cast<OWeakObject *>(this) ); static_cast<OWeakObject *>(this) );
entry.release();
} }
//______________________________________________________________________________ //______________________________________________________________________________
@@ -448,11 +447,14 @@ void ComponentContext::removeByName( OUString const & name )
lang::WrappedTargetException, RuntimeException) lang::WrappedTargetException, RuntimeException)
{ {
MutexGuard guard( m_mutex ); MutexGuard guard( m_mutex );
::std::size_t erased = m_map.erase( name ); t_map::iterator iFind( m_map.find( name ) );
if (erased == 0) if (iFind == m_map.end())
throw container::NoSuchElementException( throw container::NoSuchElementException(
OUSTR("no such element: ") + name, OUSTR("no such element: ") + name,
static_cast<OWeakObject *>(this) ); static_cast<OWeakObject *>(this) );
delete iFind->second;
m_map.erase(iFind);
} }
// XNameReplace // XNameReplace
@@ -556,7 +558,7 @@ Any ComponentContext::lookupMap( OUString const & rName )
if (iFind == m_map.end()) if (iFind == m_map.end())
return Any(); return Any();
ContextEntry * pEntry = iFind->second; t_map::mapped_type pEntry = iFind->second;
if (! pEntry->lateInit) if (! pEntry->lateInit)
return pEntry->value; return pEntry->value;
@@ -689,6 +691,11 @@ ComponentContext::~ComponentContext()
#ifdef CONTEXT_DIAG #ifdef CONTEXT_DIAG
::fprintf( stderr, "> destructed context %p\n", this ); ::fprintf( stderr, "> destructed context %p\n", this );
#endif #endif
t_map::const_iterator iPos( m_map.begin() );
t_map::const_iterator const iEnd( m_map.end() );
for ( ; iPos != iEnd; ++iPos )
delete iPos->second;
m_map.clear();
} }
//__________________________________________________________________________________________________ //__________________________________________________________________________________________________
void ComponentContext::disposing() void ComponentContext::disposing()
@@ -701,10 +708,10 @@ void ComponentContext::disposing()
// dispose all context objects // dispose all context objects
t_map::const_iterator iPos( m_map.begin() ); t_map::const_iterator iPos( m_map.begin() );
t_map::const_iterator iEnd( m_map.end() ); t_map::const_iterator const iEnd( m_map.end() );
for ( ; iPos != iEnd; ++iPos ) for ( ; iPos != iEnd; ++iPos )
{ {
ContextEntry * pEntry = iPos->second; t_map::mapped_type pEntry = iPos->second;
// service manager disposed separately // service manager disposed separately
if (!m_xSMgr.is() || if (!m_xSMgr.is() ||
@@ -756,13 +763,9 @@ void ComponentContext::disposing()
// dispose tdmgr; revokes callback from cppu runtime // dispose tdmgr; revokes callback from cppu runtime
try_dispose( xTDMgr ); try_dispose( xTDMgr );
// everything is disposed, hopefully nobody accesses the context anymore...
iPos = m_map.begin(); iPos = m_map.begin();
while (iPos != iEnd) for ( ; iPos != iEnd; ++iPos )
{
delete iPos->second; delete iPos->second;
++iPos;
}
m_map.clear(); m_map.clear();
} }
//__________________________________________________________________________________________________ //__________________________________________________________________________________________________