[omniORB] Memory leak in CORBA any

David Hyde davidh@cavendish.co.uk
Tue, 26 Mar 2002 12:24:50 -0000


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.