[omniORB] Memory leak in CORBA any

bjorn rohde jensen shamus@tdcadsl.dk
Tue, 26 Mar 2002 15:56:08 +0100


Hi David,

 I am testing your examples with omniORB4 on linux using gcc 2.95.3,
and i do not see a single byte of leakage. Maybe it is a problem with
omniORB3?

Yours sincerely,

bjorn

David Hyde wrote:
> 
> Yesterday I sent a message about a leak that I was getting when receiving
> CORBA::any, but only in the release build of my app.  Unfortunately there
> were no replies.
> 
> I've knocked together a couple of small apps to demonstrate what is
> happening.  These seem to leak in the debug and the release builds.
> 
> Please, please, please can someone shed some light on this for me.
> 
> if.idl:
> struct ST
> {
>         string msg;
> };
> 
> interface IF
> {
>         void Send(in any data);
> 
>         void Shutdown();
> };
> 
> receiver.cpp:
> #include "..\if_omni.h"
> #include <iostream.h>
> 
> BOOL bRun = TRUE;
> 
> class IF_impl : public POA_IF,
>         virtual public PortableServer::RefCountServantBase
> {
> public:
>         IF_impl()
>         {
>         }
> 
>         virtual ~IF_impl()
>         {
>         }
> 
>         virtual void Send(const CORBA::Any& data)
>         {
>                 ST * s;
> 
>                 if (data >>= s)
>                 {
>                         cout << s->msg << endl;
>                 }
>         }
> 
>         virtual void Shutdown()
>         {
>                 cout << "Shutdown received" << endl;
>                 bRun = FALSE;
>         }
> };
> 
> void main(int argc, char ** argv)
> {
>         CORBA::ORB_var pORB = CORBA::ORB_init(argc, argv, "omniORB3");
> 
>         PortableServer::POA_var pPOA;
>         PortableServer::POAManager_var pPOAMan;
> 
>         CORBA::Object_var obj = pORB->resolve_initial_references("RootPOA");
>         pPOA = PortableServer::POA::_narrow(obj);
>         pPOAMan = pPOA->the_POAManager();
>         pPOAMan->activate();
> 
>         CosNaming::NamingContext_var pNS = CosNaming::NamingContext::_nil();
>         obj = pORB->resolve_initial_references("NS_Shaddow");
>         pNS = CosNaming::NamingContext::_narrow(obj);
> 
>         IF_impl * pif = new IF_impl();
>         PortableServer::ObjectId_var oid = pPOA->activate_object(pif);
>         obj = pif->_this();
> 
>         CosNaming::Name name;
>         name.length(1);
>         name[0].id = (const char *) "Receiver";
>         name[0].kind = (const char *) "";
>         pNS->rebind(name, obj);
> 
>         pif->_remove_ref();
> 
>         cout << "Ready" << endl;
> 
>         while (bRun)
>         {
>                 if (pORB->work_pending())
>                         pORB->perform_work();
>         }
> 
>         pPOA->deactivate_object(oid);
> 
>         pORB->destroy();
> }
> 
> generator.cpp:
> #include "..\if_omni.h"
> #include <stdio.h>
> 
> void main(int argc, char ** argv)
> {
>         CORBA::ORB_var pORB = CORBA::ORB_init(argc, argv, "omniORB3");
> 
>         CORBA::Object_var Obj;
> 
>         CosNaming::NamingContext_var pNS = CosNaming::NamingContext::_nil();
>         Obj = pORB->resolve_initial_references("NS_Shaddow");
>         pNS = CosNaming::NamingContext::_narrow(Obj);
> 
>         CosNaming::Name name;
>         name.length(1);
>         name[0].id = (const char *) "Receiver";
>         name[0].kind = (const char *) "";
> 
>         Obj = pNS->resolve(name);
> 
>         IF_var pIF = IF::_narrow(Obj);
> 
>         if (pIF == IF_Helper::_nil())
>         {
>                 printf("Couldn't resolve object\n");
>                 exit(0);
>         }
> 
>         CORBA::Any any;
>         ST t;
> 
>         char szMsg[20];
> 
>         for (int a = 1 ; a <= 1000 ; a++)
>         {
>                 sprintf(szMsg, "Message No: %d\n", a);
>                 t.msg = (const char *) szMsg;
> 
>                 printf("Sending %s", szMsg);
>                 any <<= t;
> 
>                 pIF->Send(any);
> 
>                 ::Sleep(200);
>         }
> 
>         ::Sleep(2000);
>         pIF->Shutdown();
>         ::Sleep(2000);
> 
>         pORB->destroy();
> }
> 
> David Hyde
> Designer
> Cavendish
> Admiral House, St Leonards Road
> Windsor, Berkshire, SL4 3BL
> United Kingdom
> 
> Tel:  +44 (0) 1753 836600
> DDI: +44 (0) 1753 836619
> Fax: +44 (0) 1753 855021
> 
> Web: www.cavendish.co.uk <http://www.cavendish.co.uk/>
> 
> This email is copyright ©2002  The Cavendish Organisation Ltd. All Rights
> Reserved. The content of the email is confidential and only for disclosure
> to the intended recipient(s). This email does not constitute a formal order,
> instruction or statement on behalf of the company.