[omniORB] segfault - bug or not?

baileyk at schneider.com baileyk at schneider.com
Fri Oct 24 12:07:12 BST 2003


An IDL string maps to a C char*.  The assignment of a string to a sequence
or struct member uses the constness of the char* to determine whether a
deep copy must be made.  Your first example lost the const when it assigned
to a param_str, which is just a char*.  Then the sequence thought it was
taking ownership of the string and tried to delete it causing the SEGV.
The second example did not lose the const and so the sequence made its own
deep copy of the string.

I tend to not rely on the const overloading of the assignment operator and
always use CORBA::string_dup() to copy strings into a sequence or struct
member.  The exception to this is if the string is alread a member or held
by a CORBA::String_var.  In these cases the string member or _var objects
take care to make a deep copy.

So your code should look like this to make the deep copy explicit.

   param_seq my_p;
   my_p.length(1);
   param_str one1;
   one1 = "some string";
   my_p[0] = CORBA::string_dup(one1);


Kendall




                                                                                                                                      
                      Johan Cronje                                                                                                    
                      <jcronje at dsp.sun.ac.za>              To:       omniorb-list at omniorb-support.com                                 
                      Sent by:                             cc:                                                                        
                      omniorb-list-bounces at omniorb-        Fax to:                                                                    
                      support.com                          Subject:  [omniORB] segfault - bug or not?                                 
                                                                                                                                      
                                                                                                                                      
                      10/24/2003 10:43 AM                                                                                             
                                                                                                                                      
                                                                                                                                      




-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Good day

I am in the process of writing a corba application, and have encountered an

interesting situation while testing my application. In my idl file I have
the
following:

   typedef string param_str;
   typedef sequence<param_str> param_seq;

Now in my test implementation I have the following to test my application.

   param_seq my_p;
   my_p.length(1);
   param_str one1;
   one1 = "some string";
   my_p[0] = one1;

This generates SIGSEGV as soon as the program finishes and ~param_seq() is
called (it calls some other string sequence destructors and generates the
signal in /lib/libc.so.6 (_int_free to be precise)).

If I change it to

   param_seq my_p;
   my_p.length(1);
   my_p[0] = "some string";

everything is OK. Is this normal? If so, why doesn't my first attempt work?

Note that I am not running it as a CORBA app yet, I am still implementing
my
interface methods and wrote a small test application that only uses the
methods declared in my IDL file. Surely it should work OK?

Thank you and Best Regards
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)

iQEVAwUBP5lIreEeclgONaRbAQJ3jgf/SCkWjde6x4nAHAzyhz9kx0geCrDMCsIq
WPo8JjWWQXKv+NUNyAEcHJ2oIfYWiQPEpkO8vJUby7KbIAzd7ZcJS1mjFaPbl0zJ
sxzZy7YREnAYJMBuclbACci/U80FH/+c8wn/IsN8H5PKhFgd1EZ+i1dIl3hiRMGu
3SiyHXPzyBu0/bcQ1TalZYXutBtI/Th4FKmUxyCKgsBbNNxhaNgIsm0iIIQuhjAA
oljOTX3KR3xCiDtYXJZBhis+uWJD9j2HBiUdHSbM5kJEE5tEyBuv/sW/UBxS+dts
KFeNkIi78OWicM5IOjCR5FvmA3S0NbXP/5N+LZvYdOFLuB58imvppw==
=CCGw
-----END PGP SIGNATURE-----


_______________________________________________
omniORB-list mailing list
omniORB-list at omniorb-support.com
http://www.omniorb-support.com/mailman/listinfo/omniorb-list








More information about the omniORB-list mailing list