[omniORB] Resizing a string sequence

Johan Cronje jcronje at dsp.sun.ac.za
Mon Nov 24 23:31:36 GMT 2003


-----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!

Thank you for the help

Greets
Johan
- -- 
"There is beauty in simplicity"		-- Johan Cronje
- ---------------------------------------------------------------
Johan Cronje
Digital Signal Processing / Telecommunications Group
Electrical and Electronic Engineering Department
University of Stellenbosch
http://www.dsp.sun.ac.za/~jcronje
- ---------------------------------------------------------------
GNUPG Key: http://www.dsp.sun.ac.za/~jcronje/jcronje.asc
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2-rc1-SuSE (GNU/Linux)

iQEVAwUBP8J4wOEeclgONaRbAQK/hggAtIDrtZ7LPGmBSF7I3rksBHX1dKMmZ8P5
CL0uKUxDj6K8Q9gPawYukxYRc6j0c0L3jHYlY5mhcT7Ro1sM6rz1Ea5r0yBrIpBJ
zV50hXLaSqkt9podfQZYwsWgaDOGmvGwVCRzwXm6lqyIiy2HBoSs3E08j4xNyb5W
JKRVE28Ej0TWXLktaCSYtCuJ3MDnAqnEoG7Dvw2g4WGexZx7cYj1XQdZlhKv35Kr
geFEVRcBCbSLjW90dOvTE26kUE5wSSj5VOPyCCD22Guz5kvlp7zkirAbDW0RMqtM
XcAcsYAnfe/Fc220nvVRxUDge7a0qoSHgdvWS+p02i5TlkQFneV5zQ==
=LFQQ
-----END PGP SIGNATURE-----




More information about the omniORB-list mailing list