[omniORB] Huge Memory Leak while using DynAny in omniORB4

Alfonso Tames alfonso@tames.com
Sun Jan 19 00:55:03 2003


The memory leaking is so huge that maybe I am doing something stupid,
but I still can't find what it could be.

I am using omniORB4 and tried with RedHat8.0+gcc3.2 and
RedHat7.3+gcc2.96 getting similar results.

I am trying to pass a DynStruct to a function using a dii client.

** * ** I have this idl ** * **

module alfonso {
        interface prueba {
                short test(in string nombre, in any cosa);
        };
};


** * ** This is my server  (i will omit the main function) ** * **

class prueba_i : public POA_alfonso::prueba {
public:
  inline prueba_i() {}
  virtual ~prueba_i() {}
  virtual CORBA::Short test(const char* nombre, const CORBA::Any& cosa);
};

CORBA::Short prueba_i::test(const char* nombre, const CORBA::Any& a) {

  //DynAny
  CORBA::Object_var obj =  
               orb->resolve_initial_references("DynAnyFactory");
  DynamicAny::DynAnyFactory_ptr dafact = 
               DynamicAny::DynAnyFactory::_narrow(obj);

  DynamicAny::DynAny_var dv = dafact->create_dyn_any(a);
  DynamicAny::DynStruct_var ds = DynamicAny::DynStruct::_narrow(dv);
  DynamicAny::NameValuePairSeq* sq = ds->get_members();
  for (int i=0; i <=1; i++)
    {
      char *n;
      n = (*sq)[i].id;
      char *v;
      (*sq)[i].value >>= v;
      //cout << "Key=Value: " << n << "=" << v << endl;
    }

  //uncommenting these won't help.
  //ds->destroy();
  //dv->destroy();
  CORBA::release(dafact);
  return 1;
}


** * **  * ** * And this is the dii client   * ** * ** ** * **

int main(int argc, char **argv) {

  
  try {
      CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "omniORB4");
      CORBA::Object_var objs = orb->string_to_object(argv[1]);

      //*** DynAny Construction ***//

      //factory
      CORBA::Object_var obj =              
                    orb->resolve_initial_references("DynAnyFactory");
      DynamicAny::DynAnyFactory_ptr dafact = 
                    DynamicAny::DynAnyFactory::_narrow(obj);

      //typecode
      //struct elements:
      CORBA::StructMemberSeq carsms;
      carsms.length(2);
      carsms[0].name = CORBA::string_dup("vin");
      carsms[0].type = CORBA::TypeCode::_duplicate(CORBA::_tc_string);
      carsms[1].name = CORBA::string_dup("plates");
      carsms[1].type = CORBA::TypeCode::_duplicate(CORBA::_tc_string);

      CORBA::TypeCode_var cartc = 
               orb->create_struct_tc("IDL:struct:1.0","struct",carsms);

      //use the factory to create the DynAny
      obj = dafact->create_dyn_any_from_type_code(cartc);
      DynamicAny::DynStruct_var carstruct =  
                         DynamicAny::DynStruct::_narrow(obj.in());

      carstruct->insert_string(CORBA::string_dup("VINIVENI123"));
      carstruct->next();
      carstruct->insert_string(CORBA::string_dup("753SMM"));

      CORBA::release(dafact);

      //Create the Any:

      CORBA::Any_var someCar;
      someCar = carstruct->to_any();
      carstruct->destroy();

      //*******************************//

      // Create 100,000 requests:
      CORBA::String_var arg = (const char*) "Hello!";

      CORBA::Request_var req;
      int t = 100000;
      int m = 0;
      cout << "Performing " << t << " operations." << endl;
      for (int n=0; n<t; n++) {
        req = objs->_request("test");
        req->add_in_arg() <<= arg;
        req->add_in_arg() <<= someCar;
        req->set_return_type(CORBA::_tc_short);
        req->invoke();
        if (m==1000) {cout << n << endl; m=0;} m++;
      }
      orb->destroy;
  }
  catch(...) {}
}


I am performing this test using two different machines. The client as it
is shown, performs 100,000 requests, if ran two or three times, the
server can consume hundreds of megs  !!!

Is there a problem in my program ? Please help.


-- 
Alfonso Tames <alfonso@tames.com>
Mercadio