[omniORB] Memory leak in CORBA any
David Hyde
davidh@cavendish.co.uk
Tue, 26 Mar 2002 13:49:54 -0000
I'm doing things exactly as shown in Henning & Vinoski. If I extract =
to a
const ST* then the result is the same. Infact the operator >>=3D(st *) =
simply
calls the operator>>=3D(const st *) anyway.
I've been tracing through the omniORB source hoping to find out what is
going wrong. I've found the place in class Any where it creates an =
AnyP,
then apparently passes ownership of the data to the AnyP during inline =
void
AnyP::setCachedData(void *data, void (*destructor)(void *)) along with =
a
pointer to a destructer function that should (again presumably) clear =
up.
However, the Any destructor which destroys the AnyP object never seems =
to
get called.
Is this why the memory is leaking???
Thanks
David
-----Original Message-----
From: Clemens Fischer [mailto:fischer.c@stn-atlas.de]
Sent: 26 March 2002 12:51
To: 'David Hyde'
Subject: AW: [omniORB] Memory leak in CORBA any
Hi,
the problem is possibly in IF_impl::Send(), where an ST* instead of
a const ST* is extracted from the any. As far as i know, the standard
says that extraction of complex types is to be done by const pointer
and the any still manages the memory after extraction.
Maybe omniORB copies the data when extracting to non-const pointer?
Clemens Fischer
-----Urspr=FCngliche Nachricht-----
Von: owner-omniorb-list@uk.research.att.com
[mailto:owner-omniorb-list@uk.research.att.com]Im Auftrag von David =
Hyde
Gesendet am: Dienstag, 26. M=E4rz 2002 13:25
An: OmniOrb mailing list (E-mail)
Betreff: [omniORB] Memory leak in CORBA any
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 =3D 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 >>=3D s)
{
cout << s->msg << endl;
}
}
virtual void Shutdown()
{
cout << "Shutdown received" << endl;
bRun =3D FALSE;
}
};
void main(int argc, char ** argv)
{
CORBA::ORB_var pORB =3D CORBA::ORB_init(argc, argv, "omniORB3");
PortableServer::POA_var pPOA;
PortableServer::POAManager_var pPOAMan;
CORBA::Object_var obj =3D pORB->resolve_initial_references("RootPOA");
pPOA =3D PortableServer::POA::_narrow(obj);=20
pPOAMan =3D pPOA->the_POAManager();
pPOAMan->activate();
CosNaming::NamingContext_var pNS =3D CosNaming::NamingContext::_nil();
obj =3D pORB->resolve_initial_references("NS_Shaddow");
pNS =3D CosNaming::NamingContext::_narrow(obj);
IF_impl * pif =3D new IF_impl();
PortableServer::ObjectId_var oid =3D pPOA->activate_object(pif);
obj =3D pif->_this();
CosNaming::Name name;
name.length(1);
name[0].id =3D (const char *) "Receiver";
name[0].kind =3D (const char *) "";
pNS->rebind(name, obj);
pif->_remove_ref();
cout << "Ready" << endl;
=09
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 =3D CORBA::ORB_init(argc, argv, "omniORB3");
CORBA::Object_var Obj;
CosNaming::NamingContext_var pNS =3D CosNaming::NamingContext::_nil();
Obj =3D pORB->resolve_initial_references("NS_Shaddow");
pNS =3D CosNaming::NamingContext::_narrow(Obj);
CosNaming::Name name;
name.length(1);
name[0].id =3D (const char *) "Receiver";
name[0].kind =3D (const char *) "";
Obj =3D pNS->resolve(name);
IF_var pIF =3D IF::_narrow(Obj);
if (pIF =3D=3D IF_Helper::_nil())
{
printf("Couldn't resolve object\n");
exit(0);
}
CORBA::Any any;
ST t;
char szMsg[20];
for (int a =3D 1 ; a <=3D 1000 ; a++)
{
sprintf(szMsg, "Message No: %d\n", a);
t.msg =3D (const char *) szMsg;
printf("Sending %s", szMsg);
any <<=3D 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 =A92002 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.