[omniORB] Overloading the new and delete operators and the omniORB

Sai-Lai Lo S.Lo@orl.co.uk
Wed, 29 Apr 1998 10:39:14 +0100


>>>>> Tom Haggie writes:

> Hello,
> In our code we have overloaded the new and delete operators 
> to give us some extra functionality. However, in the omni code
> it is possible (through the inlines) for something to be created
> with new in the omni code and destroyed with the delete in
> our code thus causing an exception as we always allocate more
> memory than is needed to store extra information we need. So
> our delete is trying to delete one of the omni memory blocks 
> rather than one of is own and so frees the wrong pointer.

> The code that's giving us grief is in omniIternal.h

>   inline ~omniRopeAndKey() { 
>     if (pd_keysize > sizeof(omniObjectKey)) {
>       delete [] pd_keyptr;  // calls our delete rather than omni's
>     }
>   }

> Has anyone come across this problem before and more
> importantly does anyone have any suggestions as to how
> we can solve this problem?

I think the code that gives you grief is in the omniORB2 runtime DLL and
not the stub code that is linked into your program. The DLL uses the
default new and delete. For example, pd_keyptr in your example is allocated
in the DLL.

I believe this is a common problem with Windows NT/95. For instance, you
cannot debug a program which is linked with a non-debug DLL for the same
reason.

The solution is to rebuild the omniORB2 runtime DLL, include your
overloaded new and delete operators in the header (CORBA_sysdep.h). If the
operators are not inline, then you have to provide the object file in
the link stage of the DLL. (Have a look at the relevant section in
<top>/src/lib/omniORB2/sharedlib.)

Another alternative is not to use the omniORB2 runtime DLL and link it
statically into your executable. This may be what you want to do first to
verify whether my deduction is correct.

Regards,

Sai-Lai