[omniORB] Memory leak from an exception

Jonathan Buchanan buchanan@olsen.ch
Thu, 09 Sep 1999 11:50:42 +0200


Following from yesterday's discussion, I think this is an example of a
memory leak involving exceptions, caused when
CosNaming::NamingContext::NotFound is thrown and caught:


MLK: 98 bytes leaked in 2 blocks
This memory was allocated from:
      malloc         [rtlib.o]
      __0OnWuI       [libC.a]
      operator new(unsigned int) [rtlib.o]
      static CORBA::string_alloc(unsigned long) [libomniORB2.a]
      static OmniProxyCallWrapper::invoke(omniObject*, OmniProxyCallDesc&) [libomniORB2.a]
      CosNaming::_proxy_NamingContext::resolve(const _CORBA_Unbounded_Sequence<CosNaming::NameComponent>&) [libomniORB2.a]
      OorbOmniORB2Services::resolveName(RWCString, RWCString) [OorbOmniORB2Services.cc:212]
             if ( ! CORBA::is_nil( rootContext ) ) {

                 try {
      =>             result = rootContext->resolve( serviceName );
                 }
                 catch( CosNaming::NamingContext::NotFound& ) {
                     result = CORBA::Object::_nil();
      OisService::subscribeToTickListener(const RWCString&, const RWCString&) [OisService.cc:115]
      OisService::subscribeToTickListeners(void) [OisService.cc:93]
      OisService::init(void) [OisService.cc:68]
      OisServiceFactoryImpl::createServiceBuffer(const char*) [OisServiceFactoryImpl.cc:83]
      _sk_OisServiceFactory::dispatch(GIOP_S&, const char*, unsigned char) [OisServiceFactorySK.cc:79]
Block of 49 bytes (2 times); last block at 0x3bab48

The complete block of code in question is:


CORBA::Object_ptr OorbOmniORB2Services::resolveName(
    RWCString name,
    RWCString kind )
{
    // Prepend name with base context name if missing
    if ( name.first( '/' ) != 0 ) name.prepend( defaultNamingContext_ );

    ODEBUG( thisClass ) << "resolveName " << name << " " << kind << ENDM;

    // Tokenize the name into a collection of individual names
    RWTValSlist<RWCString> names;
    RWCTokenizer next( name );
    RWCString aName;
    while ( ! ( aName = next( "/" ) ).isNull() ) names.append( aName );

    // Probably not many names so use indexed access instead of an iterator
    int numNames = names.entries();
    CosNaming::Name serviceName;
    serviceName.length( numNames );
    for ( int i = 0; i < numNames; ++i ) {
        serviceName[ i ].id = names.at( i ).data();     // String copied
        serviceName[ i ].kind = ( i < numNames - 1 )
            ? (const char*) "NamingContext"             // String copied
            : kind.data();                              // String copied
    }
    // Use the root naming context to resolve the complete name
    CORBA::Object_ptr result = CORBA::Object::_nil();
    CosNaming::NamingContext_var rootContext = rootNamingContext();
    if ( ! CORBA::is_nil( rootContext ) ) {

        try {
            result = rootContext->resolve( serviceName );
        }
        catch( CosNaming::NamingContext::NotFound& ) {
            result = CORBA::Object::_nil();
        }
    }
    return result;
}

This was on Solaris 2.5.1 running OmniORB2 v2.7.1.

Hope it helps.

Regards,
Jon