[omniORB] Problems with method returning a complex structure

Andy Weber Andy@arcontech.com
Thu, 29 Jun 2000 16:24:23 +0100


Hi,

We are trying to develop an interface (recordData) which has a method
called refresh that *returns* a structure called updates.  updates is
composed of a sequence of sequences of data items - see japi.idl in the
enclosed ZIP file.

I have made various attempts to get the server (omniORB, tie-
implementation, C++, NT4, MSDEV version 6.0) to work, but none are
successful, no doubt because I am new to CORBA.

The refresh method does something like this:

updates * recordData_i::refresh()
{
        updates         *Result;        // has to be new'd!!
//      updates         *Ans;

        Result = new updates();
        Result->recordUpdates = recordSequence();
        
        recordSequence& rs = Result->recordUpdates;
        rs[0].recordName = (const char *) "JIM";
        rs[0].recordFields = fields();

        fields&  fs = rs[0].recordFields;
        fs.length( 2);
        fs[0].fieldName = (const char *) "NITTY GRITTY";
        fs[0].value = (const char *) "HO-HO";
        fs[1].fieldName = (const char *) "ARTHUR";
        fs[1].value = (const char *) "POOP-POOP";

//      Ans = new updates( *Result);            // blows up
//      delete Result;                          // blows up
//      return Ans;                             // blows up

        return new updates( *Result);   // has to be copied - why?? -
//                                      // Also leaks memory
}

This version 'works', but leaks memory, probably for the fairly obvious
reason that I return a *copy* of Result, but don't delete Result.  

However, if I attempt to delete Result, as in the commented-out lines
just above, the program crashes with a heap de-allocation error in some
unknown thread.

My original attempt was like this:

updates * recordData_i::refresh()
{
        updates         *Result;        // has to be new'd!!

        Result = new updates();
        ...
        return Result;
}

which I would have thought the most obvious way to write it, but it also
crashed with a similar heap error.

So basically the situation is that the best attempt eats up memory.
What am I doing wrong, and where can I get more info on the 'rules'?

The java client is also in the enclosed ZIP file.

Can anybody help?

Thanks,

Andy Weber

[demime 0.97b removed an attachment of type application/zip]
-- 
Andy Weber
Arcontech Ltd                           Phone +44 (0) 20 7405 2111
31-35 Kirby Street                      Fax   +44 (0) 20 7831 6667
London EC1N 8TE                         E-mail andy@arcontech.com

Disclaimer Notice:

This email, and any files transmitted with it, is confidential and intended
solely for the use of the individual or entity to whom it is addressed.

If you have received this mail in error please notify Arcontech Limited on 
+44 171 405 2111 or email mail@arcontech.com.

It is the responsibility of the recipient to ensure that it is virus free and no
responsibility is accepted by Arcontech Limited for any loss or damage arising
in any way from its use.