[mico-devel] not allowed to CORBA::release(baseIF) immediately after _narrow(baseIF)?

Frank Bergemann FBergemann at web.de
Wed Jun 13 12:40:07 PDT 2007


Hi

following the description in "Advanced CORBA Programming with C++" (1999), chapter 7.9.1 "Initial Reference/Conversion from String to Reference" (page #246), i used CORBA::release(obj) on the return for obj=orb->string_to_object(IOR_string), after having done MyObj ptr = MyObj::_narrow(obj) to the target object - though MyObj ptr is still in use!

To show the problem i reduced and modified $MICO_DIR/demo/poa/account-3/client.cc - pls. see below.
After a while it crashes with coredump.

There is no problem, if i delay the CORBA::release(obj) after having done CORBA::release(ptr)

Is the book wrong in telling, that i can release the base interface that early?

TIA!

rgds!

Frank

----------------------------------------------------------------------------------------------------------------

/*
* Client for our persistent server. In order to demonstrate transparent
* reactivation of the server (by micod), we explicitly shut down the
* bank after each operation.
*/

#include <sstream>

#include "account.h"

#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif

#ifdef _WIN32
#include <direct.h>
#endif


using namespace std;
template <class T>

static std::string StringFromStreamable(T &t)
{
std::ostringstream oss;
oss << t;
return oss.str();
}

int
main (int argc, char *argv[])
{
CORBA::ORB_var orb(CORBA::ORB::_nil());

for (int x=0; x<200; ++x) {

if (CORBA::is_nil(orb)) {
cout << endl;
orb = CORBA::ORB_init (argc, argv);
cout << "optained ORB" << endl;
}

/*
* IOR is in Bank.ref in the local directory
*/

char pwd[256], uri[300];
sprintf (uri, "file://%s/Bank.ref", getcwd(pwd, 256));

/*
* Connect to the Bank
*/

CORBA::Object_var obj;
Bank_var bank;
try {
obj = orb->string_to_object (uri);
bank = Bank::_narrow (obj);
CORBA::release(obj); // PUTTING CORBA::release(...) HERE CAUSES CORE-DUMP !!!
}
catch (CORBA::Exception &e) {
std::cerr << "failed to optain 'Bank' object: " << StringFromStreamable(e) << std::endl;
exit (1);
}

cout << "optained 'Bank' object" << endl;

if (CORBA::is_nil (bank)) {
cout << "oops: could not locate Bank" << endl;
exit (1);
}

CORBA::release(bank);
cout << "released 'Bank' object" << endl;

// CORBA::release(obj); // PUTTING CORBA::release(...) HERE is OK

/*
orb->shutdown(true);
orb->destroy();
*/

CORBA::release(orb);
cout << "released ORB" << endl;
orb = CORBA::ORB::_nil();

usleep(250000);
}
return 0;
}


_____________________________________________________________________
Der WEB.DE SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
http://smartsurfer.web.de/?mc=100071&distributionid=000000000066



More information about the Mico-devel mailing list