[omniORB] Resizing a string sequence
Gary Duzan
gduzan at bbn.com
Mon Nov 24 16:46:14 GMT 2003
In Message <200311242331.44727.jcronje at dsp.sun.ac.za> ,
Johan Cronje <jcronje at dsp.sun.ac.za> wrote:
=>-----BEGIN PGP SIGNED MESSAGE-----
=>Hash: SHA1
=>
=>On Monday 24 November 2003 22:55, Gary Duzan wrote:
=>> In Message <200311241740.21950.jcronje at dsp.sun.ac.za> ,
=>> Johan Cronje <jcronje at dsp.sun.ac.za> wrote:
=>>
=>> =>protected:
=>> => attribute_list component_attr;
=>> =>// this is a global variable, as it is returned by following function
=>> =>
=>> => attribute_list* return_attributes()
=>> => {
=>> => ...
=>> => 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);
=>> => }
=>> => ...
=>> => }
=>>
=>> Are you returning &this->component_attr here? You can't do that.
=>> Since "the caller owns the memory", the ORB will try to delete your
=>> sequence object and fail, potentially causing all sorts of nastiness
=>> similar to what you are seeing. You'll have to allocate and return a
=>> new sequence object each time.
=>
=>Yep, I returned the global component_attr. I am gonna try the following,
=>if you guess it will work, you don't need to reply, as (assuming it works)
=>I'll have the answer.
=>
=> attribute_list *component_attr;
=>
=>Then in the fn:
=> attribute_list* return_attributes()
=> {
=> ...
=> delete component_attr; // remove old value
=> component_attr = new attribute_list;
=> for (....)
=> (*component_attr)[i] = ...
=> ...
=> return component_attr;
=> }
=>
=>If there is something horribly wrong with this approach, _please_ let me know!
Only that you are keeping an invalid pointer to the sequence around
for no reason. If you really want to have a copy of the sequence, go
ahead and make it a member, populate it, and:
return new attribute_list(component_attr);
or something like that. Otherwise, just make component_attr a local.
Gary Duzan
BBN Technologies
A Verizon Company
More information about the omniORB-list
mailing list