[omniORB] HUGE memory leaks

Sai-Lai Lo S.Lo@uk.research.att.com
15 Feb 2000 14:09:52 +0000


Firstly, you are not using the sequence mapping properly but I don't think
this is causing your leak.

You are releasing an object reference which is managed by a _var type
explicitly. This cause the object to be released twice and the consequence
is unpredictable.

Why is it necessary to repeatedly initialise the ORB and destroy in every
call? This is very costly in terms of execution time. You only have to do
this once on startup and once on shutdown. I could well believe that there
are singletons inside the ORB that causes memory leak if you do ORB_init and
orb->NP_destroy() repeatedly. Also there is no need to initialise a BOA if
you do not have a CORBA object instantiated in your address space.

See my comments below.

Perhaps its time to read a good CORBA programming book :-)

Sai-Lai

>>>>> John Cumming writes:


> void AnSASendMessage(uchar messageType, uchar entryPoint, uchar errorCode,
> char
> * messageData)
> {
>     // IDL defined type
>     byteStream message;

>     try{ // try connection to messsage handler and register the project
> start
>         Message_Job jobMessage;
>         char dataBuffer[128] = {0};

>         (.... fill structure)
    
>         int messageSize = ( (sizeof(jobMessage)-sizeof(char*)) +
> sizeof(dataBuffer) + 1);

>         message.length(messageSize);


> XXX        memcpy(&message[0], &jobMessage,
> XXX(sizeof(jobMessage)-sizeof(char*)));
> XXX        memcpy(&message[(sizeof(jobMessage)-sizeof(char*))], dataBuffer,
> XXXsizeof(dataBuffer));


Better use the get_buffer() method to get a pointer to the buffer if you
want to do memcpy.

        CORBA::Octet* buf = message.get_buffer();
        memcpy(buf,(void*)&jobMessage,(sizeof(jobMessage)-sizeof(char*)));
        memcpy(buf+(sizeof(jobMessage)-sizeof(char*)), dataBuffer, sizeof(dataBuffer));


>     }catch(...){
>         .... exception handling
>     }

>     try{
>         int argc = 0;

        
> XXX        CORBA::ORB_ptr orb = CORBA::ORB_init(argc, NULL, "omniORB2");
> XXX        CORBA::BOA_ptr boa = orb->BOA_init(argc, NULL, "omniORB2_BOA");

          static CORBA::Boolean initialised = 0;
          static CORBA::ORB_ptr orb;
      
          if (!initialised) {
             orb = CORBA::ORB_init(argc, NULL, "omniORB2");
          }  

>         CORBA::Object_var obj = getObjectReference(orb);
>         AnSAMessageHandler_var messageHandler =
> AnSAMessageHandler::_narrow(obj);

>         CORBA::Short Error = messageHandler->AnSASendMessage(message);


> XXX        message.release();       // XXX this is a read only method
>                                     //     which does not do what you think
>                                     //     it does. The sequence dtor will
>                                     //     clean itself up when this function returns.
> XXX       CORBA::release(obj);      // XXX Don't do that! obj is already
>                                     // a _var type, it will be released
>                                     // automagically once this function returns.

> XXX        boa-> destroy();         // no need for a boa
> XXX        orb-> NP_destroy();      // Don't do that until your program
>                                        is ready to exit.

-- 
Sai-Lai Lo                                   S.Lo@uk.research.att.com
AT&T Laboratories Cambridge           WWW:   http://www.uk.research.att.com 
24a Trumpington Street                Tel:   +44 1223 343000
Cambridge CB2 1QA                     Fax:   +44 1223 313542
ENGLAND