[omniORB] deriving from servant class

Ulf Stoermer ulf@emi.yamaha.co.jp
Fri Mar 7 08:23:01 2003


Hello,
this is a question for the experts and a little bit difficult to explain,
so please bear with me.

Simplified, I have following two classes:

class CModel : public POA_Basic::Model, public
PortableServer::RefCountServantBase
{
   CModel() { this->_this() ; ) ;
} ;

class CDerivedModel : public CModel
{
   CDerivedModel() {} ;
} ;

In the main function I initialize the orb and then "new" an object
of type CDerivedModel. When in turn the constructor of CModel
is called the object gets activated by _this().
This works very well and without a problem.

But now, if I add just one member variable to CDerivedModel
things get out of hand, e.g.

class CDerivedModel : public CModel
{
   CDerivedModel() {} ;
   int dummy ;
} ;

During the invocation chain that is initiated by the call to _this()
I end up in the function omniOrbPOA::servant__this( PortableServer::Servant
p_servant,
const char* repoId) from where then p_servant->_add_ref() is called.

If I now step with the debugger into this function, then I end up
in PortableServer::RefCountServantBase::_add_ref()
But in here suddenly I have an invalid this pointer. Well, it points into
the
memory, but not at the correct address. That's the reason why then the
call to pd_refCount++ will corrupt some other object and my program crashes.

The question is, why is suddenly the 'this' pointer corrupted during
_add_ref()?
All I did was adding one dummy variable to the class CDerivedModel.

Funny enough, when I call _this() from within the constructor of
CDerivedModel
everything is fine again.

But then, I don't want to do that, because the idea is to create a
higher level class in order to hide all the Corba stuff away from the
applications
programmers in the base servant class.

This problem shows up within Omni4 and both on Linux and Win2k.
I stripped my project down to the bare bones and it is really simple to
reproduce the situation.

Is this a bug, or am I not allowed to call _this() from within the
constructor?

Any help is appreciated

Ulf