[omniORB] string problem
Glenn A. Hochberg
gah@research.att.com
Mon, 26 Mar 2001 15:13:38 -0500
It looks like the commented out line is what you want, without the other two
lines:
char* GeoDataset_i::GetMnemonic(int32 index)
{
char* ret = CORBA::string_dup(g_SrcMan->SourceMnemonic(index));
return ret;
}
The version you have below is leaking the memory you get from string_alloc()
by overwriting the pointer value with the const char* from the call; you're
String_var in the client is then going to release it, which is certainly not
what you want.
Did you try the version above?
-Glenn
Bart van den Eijnden wrote:
> Hi,
>
> I have a problem with strings:
> - the function g_SrcMan->SourceMnemonic(index) results in a const char*
> -if I call the GetMnemonic function several times and use string_alloc,
> I only get one record back
> -if I use the string_dup method instead, I only get a few records, until
> some kind of buffer is full (?)
> -if I combine both (I have a memory leak) but it works, then if I call
> the client twice the second time I don't get anything back anymore. When
> I restart the server it's ok.
>
> Can anyone help?
>
> This is the implementation
> char* GeoDataset_i::GetMnemonic(int32 index)
> {
> char* ret = CORBA::string_alloc(80);
> ret = (char*) g_SrcMan->SourceMnemonic(index);
> //char* ret = CORBA::string_dup(g_SrcMan->SourceMnemonic(index));
> return ret;
> }
>
> This is the client:
> CORBA::String_var ret = gds->GetMnemonic(i);
> std::cerr << "The mnemonic of dataset " << i << " is: " << (char*) ret
> << std::endl;
>
> --
> Bart van den Eijnden
> Geodan SDT BV
>
> Vestiging Zuid
> Buitenhaven 27-A
> 5211 TP 's-Hertogenbosch
>
> Telefoon: 073-6925151
> Fax: 073-6925150
> Email: bart@geodan.nl
> WWW: www.geodan.nl
--
Glenn A. Hochberg | "Any activity becomes creative when the doer
AT&T Labs | cares about doing it right, or doing it better."
gah@research.att.com | -John Updike