[omniORB] Memory problem with string_out argument

Olivier Thiboutot o.thiboutot@voxco.com
Thu, 16 Nov 2000 10:20:46 -0500


This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C04FE0.CB1AE560
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hello... List !

I have a little problem with an out argument of type "string" and the
destruction...
A BIG ASSERT!!!

the IDL Interface goes like this :
interface server
{
	long get_string(out string message);
};

The problem raise from the use of "_var" type. The client call the
get_string as it follow :
{
server_ptr MyServer =3D ...; // Valid ref
CORBA::Long Result;
CORBA::String_var buffer;
...

Result =3D get_string(buffer);	// Everything goes fine and I have the
message.
cout << Buffer; 			// Everything goes fine and I see
the message.
...				// No used of buffer at all.
return Result;
}				// Crash with the String_var::~String_var()

And the line that could help me is this one. Does anybody got a hint =
for
that problem

       /*
         * If this ASSERT fails, a bad pointer has been passed in. It =
may be
         * totally bogus, or it may have been allocated from another =
heap.
         * The pointer MUST come from the 'local' heap.
         */
        _ASSERTE(_CrtIsValidHeapPointer(pUserData));   // pUserData =
realy
point to my returned string...!!! and CRASH.

Does the _out agument created by the proxy are allocated on my 'local' =
heap
?

Just to be sure, I can create and destroy string_var like this without =
any
problem :
{
	CORBA::String_var buffer =3D (const char *)"Olivier";
}

Thanks for help

      Olivier Thibout=F4t
      VOXCO Inc.
      o.thiboutot@voxco.com
      tel  : (514) 861-9255
      fax : (514) 861-9209


P.S. : this code work fine but the _var solution should work too, no ?
{
	CORBA::Long Result;
	char * Buffer;
			/*	CORBA::String_var Buffer;   */

	Result =3D get_string(Buffer);
	cout << Buffer;
	CORBA::string_free(Buffer); 	// Everything goes fine !!!!
}


------_=_NextPart_001_01C04FE0.CB1AE560
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
5.5.2652.35">
<TITLE>Memory problem with string_out argument</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=3D2 FACE=3D"Arial">Hello... List !</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Arial">I have a little problem with an out =
argument of type &quot;string&quot; and the destruction...</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">A BIG ASSERT!!!</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Arial">the IDL Interface goes like this =
:</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">interface server</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">{</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=3D2 =
FACE=3D"Arial">long get_string(out string message);</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">};</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Arial">The problem raise from the use of =
&quot;_var&quot; type. The client call the get_string as it follow =
:</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">{</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">server_ptr MyServer =3D ...; // Valid =
ref</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">CORBA::Long Result;</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">CORBA::String_var buffer;</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">...</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Arial">Result =3D =
get_string(buffer);&nbsp;&nbsp;&nbsp; // Everything goes fine and I =
have the message.</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">cout &lt;&lt; Buffer; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Everything goes fine and =
I see the message.</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">...&nbsp;&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // No used of buffer at =
all.</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">return Result;</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Crash with the =
String_var::~String_var()</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Arial">And the line that could help me is =
this one. Does anybody got a hint for that problem</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
/*</FONT>
<BR><FONT SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * If =
this ASSERT fails, a bad pointer has been passed in. It may be</FONT>
<BR><FONT SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * =
totally bogus, or it may have been allocated from another heap.</FONT>
<BR><FONT SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *<B> =
The pointer MUST come from the 'local' heap.</B></FONT>
<BR><FONT SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
*/</FONT>
<BR><FONT SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
_ASSERTE(_CrtIsValidHeapPointer(pUserData));&nbsp;&nbsp; // pUserData =
realy point to my returned string...!!! and</FONT><B> <FONT SIZE=3D2 =
FACE=3D"Arial">CRASH.</FONT></B>
</P>

<P><FONT SIZE=3D2 FACE=3D"Arial">Does the _out agument created by the =
proxy are allocated on my 'local' heap ?</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Arial">Just to be sure, I can create and =
destroy string_var like this without any problem :</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">{</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=3D2 =
FACE=3D"Arial">CORBA::String_var buffer =3D (const char =
*)&quot;Olivier&quot;;</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">}</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Arial">Thanks for help</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Olivier =
Thibout=F4t</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VOXCO =
Inc.</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
o.thiboutot@voxco.com</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
tel&nbsp; : (514) 861-9255</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fax : =
(514) 861-9209</FONT>
</P>
<BR>

<P><FONT SIZE=3D2 FACE=3D"Arial">P.S. : this code work fine but the =
_var solution should work too, no ?</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">{</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=3D2 =
FACE=3D"Arial">CORBA::Long Result;</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=3D2 =
FACE=3D"Arial">char * Buffer;</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=3D2 =
FACE=3D"Arial">/*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CORBA::String_var =
Buffer;&nbsp;&nbsp; */</FONT>
</P>

<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=3D2 =
FACE=3D"Arial">Result =3D get_string(Buffer);</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=3D2 =
FACE=3D"Arial">cout &lt;&lt; Buffer;</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=3D2 =
FACE=3D"Arial">CORBA::string_free(Buffer); &nbsp;&nbsp;&nbsp; // =
Everything goes fine !!!!</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">}</FONT>
</P>

</BODY>
</HTML>
------_=_NextPart_001_01C04FE0.CB1AE560--