[omniORB] string_dup() behavior
Lionel Gilet
lgilet@san-jose.tt.slb.com
Fri Jul 12 18:22:00 2002
Let me provide a bit more info.
I am using Visual Studio.NET and Windows 2000.
The compiler options are:
/nologo /Od /Z7 /D__WIN32__ /D__x86__ /D__NT__ /D__OSVERSION__=4
The executable is linked with:
omniORB304_rt.lib
omnithread2_rt.lib
omniDynamic304_rt.lib
The code is pretty much reduced to:
{
CORBA::String_var theString = CORBA::string_dup((const char*) "name");
}
When I reach the end of scope I get:
HEAP: Invalid Address specified to RtlFreeHeap ( 510000, 417d18 )
Again I do not get the problem if I use CORBA::String_var::string_dup() or if I link with the static
libraries.
I also tried:
{
char* newName = new char [10];
strcpy(newName, "name");
CORBA::String_var theString = CORBA::string_dup(newName);
}
and I get the same result.
CORBA::string_dup() does duplicate the string so I really do not understand why the string member can
not be deleted and why the behavior is fine with CORBA::String_var::string_dup();
Thank you for sharing your ideas,
Lionel Gilet
Schlumberger / NPtest
baileyk@schneider.com wrote:
> My guess is the problem is caused by a mix of different runtime libraries
> too. I don't run omniORB on Windows but I've done enough Windows DLL
> programming to know how easy it is to fall into that trap.
>
> I don't agree that one needs to cast all string literals. If you use
> CORBA::string_dup, you don't need to also cast the argument. If you are
> constructing a String_var directly, then yes.
>
> CORBA::String_var theString("name"); // not a good idea on all platforms
>
> CORBA::String_var theString((char const*)"name"); // more reliable
>
> But I always just use CORBA::string_dup() to make it clear that a copy is
> being made.
>
> Kendall
>
>
> "Visscher, Bruce"
> <VISSCHB@rjrt.com> To: "Lionel Gilet" <lgilet@san-jose.tt.slb.com>,
> Sent by: "OmniOrb List" <omniorb-list@realvnc.com>
> omniorb-list-admin@r cc:
> ealvnc.com Fax to:
> Subject: RE: [omniORB] string_dup() behavior
>
> 07/11/2002 08:08 PM
>
>
>
> > {
> > CORBA::String_var the String = CORBA::string_dup("name");
> > }
>
> I don't really see why this should be a problem (except for the obvious
> typo in the variable name).
>
> Are you sure you used consistent compiler options? If you link against the
> omniORB DLLs you must configure your project to compile
> and link against the multi-threaded DLL version of the MSC run time.
>
> In any case, you should always cast literal strings to "pointer to const
> char" to be on the safe side. The C++ standard mandates
> that string literals are of this type already so the cast wouldn't be
> needed with a standards conforming compiler.
>
> The CORBA C++ mapping made some unfortunate choices regarding pointers to
> non-const char.
>
> HTH,
>
> Bruce
> (See attached file: InterScan_Disclaimer.txt)
>
> ------------------------------------------------------------------------
> Name: InterScan_Disclaimer.txt
> InterScan_Disclaimer.txt Type: Plain Text (text/plain)
> Encoding: BASE64