From 586ab8fc282efa099d1d6103fffe8df415a1899d Mon Sep 17 00:00:00 2001 From: vzykov Date: Mon, 22 Oct 2007 11:55:46 +0000 Subject: ChangeLogTag: Mon Oct 22 11:50:34 UTC 2007 Vladimir Zykov --- TAO/ChangeLog | 14 ++++++++++++ TAO/examples/Simple/Simple_util.cpp | 6 +++++- TAO/examples/Simple/bank/AccountManager_i.cpp | 31 ++++++++++++++++++++------- TAO/examples/Simple/bank/AccountManager_i.h | 8 ++++--- TAO/examples/Simple/bank/Account_i.cpp | 1 - TAO/examples/Simple/bank/Bank_Client_i.cpp | 13 +++++++---- TAO/examples/Simple/bank/run_test.pl | 4 ++-- TAO/examples/Simple/grid/Grid_Client_i.cpp | 2 -- TAO/examples/Simple/grid/Grid_i.cpp | 20 ++++++++++------- TAO/examples/Simple/grid/Grid_i.h | 3 +++ 10 files changed, 73 insertions(+), 29 deletions(-) diff --git a/TAO/ChangeLog b/TAO/ChangeLog index c1e0721c327..7b6e617f7e6 100644 --- a/TAO/ChangeLog +++ b/TAO/ChangeLog @@ -1,3 +1,17 @@ +Mon Oct 22 11:50:34 UTC 2007 Vladimir Zykov + + * examples/Simple/grid/Grid_i.h: + * examples/Simple/grid/Grid_Client_i.cpp: + * examples/Simple/grid/Grid_i.cpp: + * examples/Simple/Simple_util.cpp: + * examples/Simple/bank/AccountManager_i.cpp: + * examples/Simple/bank/Bank_Client_i.cpp: + * examples/Simple/bank/AccountManager_i.h: + * examples/Simple/bank/Account_i.cpp: + * examples/Simple/bank/run_test.pl: + Fixed some more memory leaks. The example bank required quite + substantial changes. + Mon Oct 22 03:30:03 UTC 2007 Phil Mesnier * tao/DynamicInterface/AMH_DSI_Response_Handler.inl: diff --git a/TAO/examples/Simple/Simple_util.cpp b/TAO/examples/Simple/Simple_util.cpp index f8055d55ad2..bd153458f12 100644 --- a/TAO/examples/Simple/Simple_util.cpp +++ b/TAO/examples/Simple/Simple_util.cpp @@ -198,12 +198,14 @@ Server::init (const char *servant_name, template int Server::run (void) { - // Run the main event loop for the ORB. + // Run the main event loop for the ORB. if (this->orb_manager_.run () == -1) ACE_ERROR_RETURN ((LM_ERROR, "Server_i::run"), -1); + this->orb_manager_.fini (); + return 0; } @@ -347,6 +349,8 @@ template Client::~Client (void) { ACE_OS::free (this->ior_); + + this->orb_->destroy (); } template int diff --git a/TAO/examples/Simple/bank/AccountManager_i.cpp b/TAO/examples/Simple/bank/AccountManager_i.cpp index 2cc8345a076..b306eb2bddd 100644 --- a/TAO/examples/Simple/bank/AccountManager_i.cpp +++ b/TAO/examples/Simple/bank/AccountManager_i.cpp @@ -18,7 +18,12 @@ AccountManager_i::AccountManager_i (void) AccountManager_i::~AccountManager_i (void) { - // no-op + for (MAP_MANAGER_TYPE::ITERATOR iter = this->hash_map_.begin (); + iter != this->hash_map_.end (); + ++iter) + { + delete (*iter).int_id_; + } } // Set the ORB pointer @@ -93,20 +98,30 @@ AccountManager_i::close (Bank::Account_ptr account) { try { - CORBA::String_var name = - CORBA::string_dup (account->name ()); + CORBA::String_var name = account->name (); + ACE_DEBUG((LM_DEBUG, + "[SERVER] Process/Thread Id : (%P/%t) Closing Account for %s\n", + name.in ())); - if (hash_map_.unbind (name.in ()) == -1) + Account_i *account = 0; + if (hash_map_.unbind (name.in (), account) == -1) { if (TAO_debug_level > 0) ACE_DEBUG((LM_DEBUG, "Unable to close account\n")); } - else if (TAO_debug_level > 0) - ACE_DEBUG((LM_DEBUG, - "[SERVER] Process/Thread Id : (%P/%t) Closing Account for %s\n", - (char *) name)); + + if (account) + { + PortableServer::POA_var poa = account->_default_POA (); + + PortableServer::ObjectId_var id = poa->servant_to_id (account); + + poa->deactivate_object (id.in ()); + + delete account; + } } catch (const CORBA::Exception& ex) { diff --git a/TAO/examples/Simple/bank/AccountManager_i.h b/TAO/examples/Simple/bank/AccountManager_i.h index f7e37df9d97..2764a9d0941 100644 --- a/TAO/examples/Simple/bank/AccountManager_i.h +++ b/TAO/examples/Simple/bank/AccountManager_i.h @@ -85,9 +85,11 @@ private: PortableServer::POA_ptr poa_; // POA pointer. - ACE_Hash_Map_Manager hash_map_; + typedef ACE_Hash_Map_Manager MAP_MANAGER_TYPE; + + MAP_MANAGER_TYPE hash_map_; // Calls to will create a new instance of and // bind into the hash map manager if is unique, else it will // return a previously bound entry. diff --git a/TAO/examples/Simple/bank/Account_i.cpp b/TAO/examples/Simple/bank/Account_i.cpp index ca440ad854c..8f7ea9a9c00 100644 --- a/TAO/examples/Simple/bank/Account_i.cpp +++ b/TAO/examples/Simple/bank/Account_i.cpp @@ -23,7 +23,6 @@ Account_i::Account_i (const char *name, Account_i::~Account_i (void) { - CORBA::string_free (name_); } // Set the ORB pointer. diff --git a/TAO/examples/Simple/bank/Bank_Client_i.cpp b/TAO/examples/Simple/bank/Bank_Client_i.cpp index cb329902373..8cf0995d20c 100644 --- a/TAO/examples/Simple/bank/Bank_Client_i.cpp +++ b/TAO/examples/Simple/bank/Bank_Client_i.cpp @@ -88,8 +88,6 @@ Bank_Client_i::test_for_same_name (void) ACE_ASSERT (acct_id1->_is_equivalent ((CORBA::Object *) acct_id2.in ()) != 0); client->close (acct_id1.in ()); - - client->close (acct_id2.in ()); } // This method tests whether an account with different names can be opened @@ -119,7 +117,6 @@ Bank_Client_i::test_for_different_name (void) void Bank_Client_i::test_for_overdraft (void) { - CORBA::Float initial_bal = 100.0; const char *name = "Name"; Bank::Account_var acct_id = client->open (name, initial_bal); @@ -127,7 +124,15 @@ Bank_Client_i::test_for_overdraft (void) CORBA::Float bal = acct_id->balance (); - acct_id->withdraw (bal + 20); + try + { + acct_id->withdraw (bal + 20); + } + catch (Bank::Account::Overdraft &) + { + ACE_DEBUG ((LM_DEBUG, + "Overdraft caught.\n")); + } client->close (acct_id.in ()); } diff --git a/TAO/examples/Simple/bank/run_test.pl b/TAO/examples/Simple/bank/run_test.pl index 6adc9ec36ee..83f573b963b 100755 --- a/TAO/examples/Simple/bank/run_test.pl +++ b/TAO/examples/Simple/bank/run_test.pl @@ -15,7 +15,7 @@ $iorfile = PerlACE::LocalFile ("bank.ior"); unlink $iorfile; $SV = new PerlACE::Process ("server", "-o $iorfile"); -$CL = new PerlACE::Process ("client", "-f $iorfile"); +$CL = new PerlACE::Process ("client", "-f $iorfile -x"); $SV->Spawn (); @@ -32,7 +32,7 @@ if ($client != 0) { $status = 1; } -$server = $SV->TerminateWaitKill (5); +$server = $SV->WaitKill (5); if ($server != 0) { print STDERR "ERROR: server returned $server\n"; diff --git a/TAO/examples/Simple/grid/Grid_Client_i.cpp b/TAO/examples/Simple/grid/Grid_Client_i.cpp index 1091f06a98e..ae992b80da7 100644 --- a/TAO/examples/Simple/grid/Grid_Client_i.cpp +++ b/TAO/examples/Simple/grid/Grid_Client_i.cpp @@ -23,7 +23,6 @@ Grid_Client_i::Grid_Client_i (void) //Destructor. Grid_Client_i::~Grid_Client_i (void) { - ACE_DEBUG ((LM_DEBUG, "Called \n")); //no-op } @@ -106,7 +105,6 @@ Grid_Client_i::run (const char *name, client->shutdown (); } - client.orb ()->destroy (); ACE_UNUSED_ARG (ret_val); } catch (const CORBA::UserException& range_ex) diff --git a/TAO/examples/Simple/grid/Grid_i.cpp b/TAO/examples/Simple/grid/Grid_i.cpp index a15811675ba..bafc25964aa 100644 --- a/TAO/examples/Simple/grid/Grid_i.cpp +++ b/TAO/examples/Simple/grid/Grid_i.cpp @@ -20,7 +20,7 @@ Grid_i::Grid_i (CORBA::Short x, : width_ (x), height_ (y) { - ACE_NEW_THROW_EX (array_, + ACE_NEW_THROW_EX (this->array_, CORBA::Long *[y], CORBA::NO_MEMORY ()); @@ -28,7 +28,7 @@ Grid_i::Grid_i (CORBA::Short x, for (int ctr = 0; ctr < y; ctr++) { - ACE_NEW_THROW_EX (array_[ctr], + ACE_NEW_THROW_EX (this->array_[ctr], CORBA::Long[x], CORBA::NO_MEMORY ()); } @@ -39,7 +39,12 @@ Grid_i::Grid_i (CORBA::Short x, Grid_i::~Grid_i (void) { - // no-op. + for (int ctr = 0; ctr < this->height_; ctr++) + { + delete [] this->array_[ctr]; + } + + delete [] this->array_; } // Set a value in the grid. @@ -140,6 +145,7 @@ Grid_Factory_i::shutdown (void) // Constructor Grid_Factory_i::Grid_Factory_i (void) + : grid_ (0) { // no-op } @@ -148,7 +154,7 @@ Grid_Factory_i::Grid_Factory_i (void) Grid_Factory_i::~Grid_Factory_i (void) { - // no-op + delete this->grid_; } // Make a . @@ -157,8 +163,6 @@ Grid_ptr Grid_Factory_i::make_grid (CORBA::Short width, CORBA::Short height) { - Grid_i *grid_ptr = 0; - ACE_DEBUG ((LM_DEBUG, "(%P|%t) Making a new Grid\n")); @@ -172,7 +176,7 @@ Grid_Factory_i::make_grid (CORBA::Short width, // This attempts to create a new Grid_i and throws an exception and // returns a null value if it fails - ACE_NEW_THROW_EX (grid_ptr, + ACE_NEW_THROW_EX (this->grid_, Grid_i (width, height), CORBA::NO_MEMORY ()); @@ -184,7 +188,7 @@ Grid_Factory_i::make_grid (CORBA::Short width, PortableServer::POA::_narrow (poa_object.in ()); PortableServer::ObjectId_var id = - root_poa->activate_object (grid_ptr); + root_poa->activate_object (this->grid_); CORBA::Object_var object = root_poa->id_to_reference (id.in ()); diff --git a/TAO/examples/Simple/grid/Grid_i.h b/TAO/examples/Simple/grid/Grid_i.h index e1393305fb8..3bfb7e7f78e 100644 --- a/TAO/examples/Simple/grid/Grid_i.h +++ b/TAO/examples/Simple/grid/Grid_i.h @@ -100,6 +100,9 @@ public: // Set the ORB pointer. private: + Grid_i *grid_; + // This pointer is here only for proper clean up. + CORBA::ORB_var orb_; // ORB pointer. -- cgit v1.2.1