[omniORB] omniORB 4, PolicyList + destroy

Brecht Vermeulen brecht.vermeulen@rug.ac.be
Thu, 04 Oct 2001 16:22:57 +0200


Hi,

I've a question about the memory management in the following code:

  PortableServer::IdAssignmentPolicy_ptr assign =
poa->create_id_assignment_policy(PortableServer::USER_ID);
  PortableServer::RequestProcessingPolicy_ptr requestproc =
poa->create_request_processing_policy(PortableServer::USE_DEFAULT_SERVANT);
  PortableServer::ServantRetentionPolicy_ptr retention =
poa->create_servant_retention_policy(PortableServer::NON_RETAIN);
  PortableServer::IdUniquenessPolicy_ptr uniqueness =
poa->create_id_uniqueness_policy(PortableServer::MULTIPLE_ID);

  PortableServer::POA_var elementPOA;
  { 
	  CORBA::PolicyList policy_list;
	  policy_list.length(4);
	  policy_list[0] = assign;
	  policy_list[1] = requestproc;
	  policy_list[2] = retention;
	  policy_list[3] = uniqueness;
  
	  elementPOA = poa->create_POA("elements", pman, policy_list);
  };	  
	  assign->destroy();
	  requestproc->destroy();
	  retention->destroy();
	  uniqueness->destroy();

to my opinion, the assign->destroy() should give a segmentation fault or
something, because the original _ptr to the policy objects are assigned
to the sequence policy_list which takes over the memory management of
the reference (the object ref count remains 1) and if this sequence goes
out of scope it should release all its references.

And thereafter the assign->destroy() should not work anymore. (even if I
add a second assign->destroy() it doesn't crash)

I know from the archive
http://www.uk.research.att.com/omniORB/archives/1999-11/0186.html
that the destroy() in omniORB is a no-op operation and that the object
is removed when its reference count comes to 0 (which should happen when
going out of scope I think).

Is this correct or am I wrong ?

By the way, I know the destroys should be before the last '}', but I
just wanted to test this.
and Orbacus crashes indeed on this.

regards,
Brecht