[omniORB] any and src/examples/anyExample memory leak ?

HA Quoc Viet qvha@axlog.fr
Mon, 06 Sep 1999 16:54:10 +0200


Hello :o)


Does anyone know why a server has to "new" a CORBA::Any before
sending it while sending an address (on a fixed Any) will
just crash the server?


specifically, given this IDL (from omniORB's examples)

class anyExample_i : public virtual _sk_anyExample {
public:
  anyExample_i() { }
  virtual ~anyExample_i() { }
  virtual CORBA::Any* testOp(const CORBA::Any& a);
  CORBA::Any toto;
};


the following implementation of testOp will crash the server

CORBA::Any* 
anyExample_i::testOp(const CORBA::Any& a) {

toto <<= (CORBA::ULong) 314; // causes the server to crash

cout << "Returning Any containing: ULong: 314\n" << endl;
return &toto;
}


while this one, with a "new", will run just fine :


CORBA::Any* 
anyExample_i::testOp(const CORBA::Any& a) {

CORBA::Any * result = new CORBA::Any;

*result <<= (CORBA::ULong) 314 ;

cout << "Returning Any containing: ULong: 314\n" << endl;
return result;
}

If using new is the only solution, then I'll wonder about
memory leaks : there's no (easy) way to know when "result" is
no longer used to delete it, is there ?