[omniORB] Resizing a string sequence

baileyk at schneider.com baileyk at schneider.com
Mon Nov 24 15:56:02 GMT 2003


The oiginal approach appeared OK to me, depending on what the caller does
with the returned pointer.  Since your method is protected I assumed it was
not a remote method, e.g. a method defined in an IDL interface.  Gary's
conclusion that the caller (be it the ORB or otherwise) is going to assume
ownership and delete the pointer may be the root problem, but your new
version doesn't solve that since you are deleting the pointer yourself too.
In addition, both approaches have thread safety issues if this object is
being shared by multiple threads, as you suggest is the case when you call
it 'global'.  Perhaps a better approach is

void return_attributes(attribute_list& component_attr)
  {
     ...
     component_attr.length(number_of_attributes);
     for (int i = 0; i < number_of_attributes; i++){
        component_attr[i] = CORBA::string_dup(string_obtained_from_fn);
     }
     ...
  }

Or if you want to follow the CORBA convention that a method returning a
variable length type must allocate on the heap and return a pointer, then
get rid of your protected member variable altogether and allocate a new
sequence in each call (e.g. don't delete the old pointer value since it's
assumed the caller must do that when appropriate).

Kendall






More information about the omniORB-list mailing list