[omniORB] Process on Win32 crash while calling _this()

M300_ªLÀAÀs³Bªø edward_lin@iwin.com.tw
Fri Nov 8 08:39:00 2002


Hi, all

Sorry to pollute traffic because I post source code.

At the beginning, I wanted to write a CosNotification Push Consumer, but the
process was always down on Win32. And then I ported to Linux and found this
program was OK; so I reduced my program to minimum to find out what
happened. This minimum program is like ECHO sample, I just modified some
statements.

The problem is, if main() constructs PushConsumer_i, the process crash when
calling _this(), if main() constructs Echo_i(from ECHO sample) instead of
PushConsumer_i, it's OK. The only difference is, if  main() constructs
PushConsumer_i, it must link COS_400rt runtime.

I'm supperised because it is quite simple beyond my imagination.

** My Env. **
omniORB 4 (Win32 and Linux)
Microsoft Visual C++ 6, SP5
Program Setting: Win32 Release, Use MFC in a shared DLL,
Runtime:
omniORB400_rt.dll, omnithread30_rt.dll, COS400_rt.dll

To Duncan,
Will this be the side effect by COS runtime (COS400_rt.dll)?

Thank you very much!

Best Regards,
Edward

The following is the code fragment.

///// begin code fragment
// header files here
#define POA_CosNC POA_CosNotifyComm

class PushConsumer_i : public POA_CosNC::StructuredPushConsumer
        , public PortableServer::RefCountServantBase
{
public:
  StructuredPushConsumer_i() { }
  void push_structured_event( const CosN::StructuredEvent& event ) { }
  void disconnect_structured_push_consumer() { }
  void offer_change( const CosN::EventTypeSeq& added, const
CosN::EventTypeSeq& removed ) { }
};

class Echo_i : public POA_Echo
        , public PortableServer::RefCountServantBase
{
public:
  char* echoString( const char* p )
  {
    return CORBA::string_dup(p);
  }
};

int main( int argc, char* argv[] )
{
  try
  {
    CORBA::ORB_var    orb = CORBA::ORB_init( argc, argv );
    CORBA::Object_var obj;

    obj = orb->resolve_initial_references( "RootPOA" );
    PortableServer::POA_var poa = PortableServer::POA::_narrow( obj );

    PushConsumer_i* pServant = new PushConsumer_i;
    ///////Echo_i*         pServant = new Echo_i;

    PortableServer::ObjectId_var oid = poa->activate_object(pServant);

    ///// when _this() is called, process crash (Linux is OK)
    ///// but if I constructs Echo_i instead of PushConsumer_i, it's OK
    obj = pServant->_this();

    pServant->_remove_ref();
    PortableServer::POAManager_var pman = poa->the_POAManager();
    pman->activate();

    cerr << "all OK" << endl;

    orb->run();
    return 0;
  }
  catch(...)
  {
    //// Win32 complain if PushConsumer_i is constructed
    cerr << "Critical Error" << endl;
    return 1;
  }
}
////// end of code fragment