diff options
author | Phil Mesnier <mesnier_p@ociweb.com> | 2013-04-22 19:14:15 +0000 |
---|---|---|
committer | Phil Mesnier <mesnier_p@ociweb.com> | 2013-04-22 19:14:15 +0000 |
commit | ac12900e8a098862237fdc9463aa8f625a9fb207 (patch) | |
tree | e5a2043855606fa5408d788620be3649f56f68d4 | |
parent | 2842fcb9bee916fa4e7c8426f820ab30a70477ad (diff) | |
download | ATCD-ac12900e8a098862237fdc9463aa8f625a9fb207.tar.gz |
Mon Apr 22 19:13:01 UTC 2013 Phil Mesnier <mesnier_p@ociweb.com>
-rw-r--r-- | TAO/ChangeLog | 9 | ||||
-rw-r--r-- | TAO/orbsvcs/ImplRepo_Service/AsyncAccessManager.cpp | 13 | ||||
-rw-r--r-- | TAO/orbsvcs/ImplRepo_Service/ImR_Locator_i.cpp | 13 | ||||
-rw-r--r-- | TAO/orbsvcs/ImplRepo_Service/LiveCheck.cpp | 171 | ||||
-rw-r--r-- | TAO/orbsvcs/ImplRepo_Service/LiveCheck.h | 41 |
5 files changed, 215 insertions, 32 deletions
diff --git a/TAO/ChangeLog b/TAO/ChangeLog index c70fae8e24c..4d3695e610b 100644 --- a/TAO/ChangeLog +++ b/TAO/ChangeLog @@ -1,3 +1,12 @@ +Mon Apr 22 19:13:01 UTC 2013 Phil Mesnier <mesnier_p@ociweb.com> + + * orbsvcs/ImplRepo_Service/AsyncAccessManager.cpp: + * orbsvcs/ImplRepo_Service/ImR_Locator_i.cpp: + * orbsvcs/ImplRepo_Service/LiveCheck.h: + * orbsvcs/ImplRepo_Service/LiveCheck.cpp: + + Fix a memory leak related to liveness callback handlers. + Mon Apr 22 17:53:36 UTC 2013 Adam Mitz <mitza@ociweb.com> * orbsvcs/ImplRepo_Service/ImplRepo_Service.mpc: diff --git a/TAO/orbsvcs/ImplRepo_Service/AsyncAccessManager.cpp b/TAO/orbsvcs/ImplRepo_Service/AsyncAccessManager.cpp index d22a3c10ed2..1ebe4c69361 100644 --- a/TAO/orbsvcs/ImplRepo_Service/AsyncAccessManager.cpp +++ b/TAO/orbsvcs/ImplRepo_Service/AsyncAccessManager.cpp @@ -78,6 +78,7 @@ AsyncAccessManager::add_interest (ImR_ResponseHandler *rh) ACE_NEW (l, AsyncLiveListener (this->info_->name.c_str(), this, this->locator_.pinger())); + LiveListener_ptr llp(l); if (!l->start()) { if (!this->send_start_request()) @@ -196,8 +197,6 @@ AsyncAccessManager::server_is_running (const char *partial_ior, this->final_state (); } - // This is not a leak. The listener registers with - // the pinger and will delete itself when done. AsyncLiveListener *l = 0; if (this->info_->activation_mode == ImplementationRepository::PER_CLIENT) { @@ -212,6 +211,8 @@ AsyncAccessManager::server_is_running (const char *partial_ior, this, this->locator_.pinger())); } + + LiveListener_ptr llp(l); if (!l->start()) { this->status (AAM_SERVER_DEAD); @@ -511,10 +512,9 @@ AsyncLiveListener::~AsyncLiveListener (void) bool AsyncLiveListener::start (void) { - bool rtn = this->per_client_ ? this->pinger_.add_per_client_listener (this,srv_ref_.in()) - : this->pinger_.add_listener (this); - if (!rtn) - delete this; + bool rtn = this->per_client_ ? + this->pinger_.add_per_client_listener (this, srv_ref_.in()) : + this->pinger_.add_listener (this); return rtn; } @@ -529,7 +529,6 @@ AsyncLiveListener::status_changed (LiveStatus status) else { this->aam_->ping_replied (status); - delete this; } return true; } diff --git a/TAO/orbsvcs/ImplRepo_Service/ImR_Locator_i.cpp b/TAO/orbsvcs/ImplRepo_Service/ImR_Locator_i.cpp index 2bb25585243..08a256501c5 100644 --- a/TAO/orbsvcs/ImplRepo_Service/ImR_Locator_i.cpp +++ b/TAO/orbsvcs/ImplRepo_Service/ImR_Locator_i.cpp @@ -1071,7 +1071,6 @@ ImR_Locator_i::find return; } _tao_rh->find (imr_info.in()); - // delete imr_info; } void @@ -1328,10 +1327,14 @@ bool ImR_Locator_i::is_alive (UpdateableServerInfo& info) { this->connect_server (info); - SyncListener listener (info->name.c_str(), - this->orb_.in(), - this->pinger_); - return listener.is_alive(); + SyncListener *listener = 0; + ACE_NEW_RETURN (listener, + SyncListener (info->name.c_str(), + this->orb_.in(), + this->pinger_), + false); + LiveListener_ptr llp(listener); + return listener->is_alive(); } int diff --git a/TAO/orbsvcs/ImplRepo_Service/LiveCheck.cpp b/TAO/orbsvcs/ImplRepo_Service/LiveCheck.cpp index 73551e2f3b2..f7f5890ae02 100644 --- a/TAO/orbsvcs/ImplRepo_Service/LiveCheck.cpp +++ b/TAO/orbsvcs/ImplRepo_Service/LiveCheck.cpp @@ -7,14 +7,160 @@ #include "ace/High_Res_Timer.h" LiveListener::LiveListener (const char *server) - : server_(server) + : server_(server), + refcount_(1), + lock_() +{ +} + +LiveListener::~LiveListener (void) { } const char * LiveListener::server (void) const { - return this->server_; + return this->server_.c_str (); +} + +LiveListener * +LiveListener::add_ref (void) +{ + ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, mon, this->lock_, 0); + ++this->refcount_; + return this; +} + +void +LiveListener::remove_ref (void) +{ + int count = 0; + { + ACE_GUARD (TAO_SYNCH_MUTEX, mon, this->lock_); + count = --this->refcount_; + } + if (count == 0) + { + delete this; + } +} + +//--------------------------------------------------------------------------- +//--------------------------------------------------------------------------- + +LiveListener_ptr::LiveListener_ptr (void) + : val_ (0) +{ +} + +LiveListener_ptr::LiveListener_ptr (LiveListener *ll) + :val_ (ll) +{ +} + +LiveListener_ptr::LiveListener_ptr (const LiveListener_ptr &ll_ptr) + :val_ (ll_ptr.clone()) +{ +} + +LiveListener_ptr::~LiveListener_ptr (void) +{ + if (val_ != 0) + { + val_->remove_ref(); + } +} + +LiveListener_ptr & +LiveListener_ptr::operator= (const LiveListener_ptr &ll_ptr) +{ + if (val_ != *ll_ptr) + { + if (val_ != 0) + { + val_->remove_ref(); + } + val_ = ll_ptr.clone(); + } + return *this; +} + +LiveListener_ptr & +LiveListener_ptr::operator= (LiveListener *ll) +{ + if (val_ != ll) + { + if (val_ != 0) + { + val_->remove_ref(); + } + val_ = ll; + } + return *this; +} + +const LiveListener * +LiveListener_ptr::operator-> () const +{ + return val_; +} + +const LiveListener * +LiveListener_ptr::operator* () const +{ + return val_; +} + +LiveListener * +LiveListener_ptr::operator-> () +{ + return val_; +} + +LiveListener * +LiveListener_ptr::operator* () +{ + return val_; +} + +bool +LiveListener_ptr::operator== (const LiveListener_ptr &ll_ptr) const +{ + return val_ == *ll_ptr; +} + +bool +LiveListener_ptr::operator== (const LiveListener *ll) const +{ + return val_ == ll; +} + +LiveListener * +LiveListener_ptr::clone (void) const +{ + if (val_ != 0) + { + val_->add_ref(); + } + return val_; +} + +LiveListener * +LiveListener_ptr::_retn (void) +{ + LiveListener * ll = val_; + val_ = 0; + return ll; +} + +void +LiveListener_ptr::assign (LiveListener *ll) +{ + if (val_ != 0) + { + val_->remove_ref(); + } + val_ = ll; } //--------------------------------------------------------------------------- @@ -78,10 +224,11 @@ LiveEntry::~LiveEntry (void) } void -LiveEntry::add_listener (LiveListener* ll) +LiveEntry::add_listener (LiveListener *ll) { ACE_GUARD (TAO_SYNCH_MUTEX, mon, this->lock_); - this->listeners_.insert (ll); + LiveListener_ptr llp(ll->add_ref()); + this->listeners_.insert (llp); } void @@ -134,14 +281,9 @@ LiveEntry::status (LiveStatus l) !i.done(); i.advance ()) { - LiveListener **ll = 0; - i.next (ll); - if (*ll != 0) + if ((*i)->status_changed (this->liveliness_)) { - if ((*ll)->status_changed (this->liveliness_)) - { - remove.insert (*ll); - } + remove.insert (*i); } } @@ -151,12 +293,7 @@ LiveEntry::status (LiveStatus l) !i.done(); i.advance ()) { - LiveListener **ll = 0; - i.next (ll); - if (*ll != 0) - { - this->listeners_.remove (*ll); - } + this->listeners_.remove (*i); } } diff --git a/TAO/orbsvcs/ImplRepo_Service/LiveCheck.h b/TAO/orbsvcs/ImplRepo_Service/LiveCheck.h index 441625c1737..1bd200b7e75 100644 --- a/TAO/orbsvcs/ImplRepo_Service/LiveCheck.h +++ b/TAO/orbsvcs/ImplRepo_Service/LiveCheck.h @@ -67,6 +67,8 @@ class Locator_Export LiveListener /// look up a listener entry in the LiveCheck map. LiveListener (const char *server); + virtual ~LiveListener (void); + /// called by the asynch ping receiver when a reply or an exception /// is received. Returns true if finished listening virtual bool status_changed (LiveStatus status) = 0; @@ -74,10 +76,43 @@ class Locator_Export LiveListener /// accessor for the server name. Used by the LiveCheck to associate a listener const char *server (void) const; + LiveListener *add_ref (void); + void remove_ref (void); + private: - const char *server_; + ACE_CString server_; + + int refcount_; + TAO_SYNCH_MUTEX lock_; }; +class LiveListener_ptr +{ +public: + LiveListener_ptr (void); + LiveListener_ptr (LiveListener *aam); + LiveListener_ptr (const LiveListener_ptr &aam_ptr); + ~LiveListener_ptr (void); + + LiveListener_ptr &operator = (const LiveListener_ptr &aam_ptr); + LiveListener_ptr &operator = (LiveListener *aam); + const LiveListener * operator-> () const; + const LiveListener * operator* () const; + LiveListener * operator-> (); + LiveListener * operator* (); + bool operator== (const LiveListener_ptr &aam_ptr) const; + bool operator== (const LiveListener *aam) const; + + LiveListener * clone (void) const; + LiveListener * _retn (void); + + void assign (LiveListener *aam); + +private: + LiveListener * val_; +}; + + //--------------------------------------------------------------------------- /* * @class LiveEntry @@ -98,7 +133,7 @@ class Locator_Export LiveEntry ImplementationRepository::ServerObject_ptr ref); ~LiveEntry (void); - void add_listener (LiveListener * ll); + void add_listener (LiveListener *ll); LiveStatus status (void) const; void status (LiveStatus l); void reset_status (void); @@ -121,7 +156,7 @@ class Locator_Export LiveEntry int max_retry_; bool may_ping_; - typedef ACE_Unbounded_Set<LiveListener *> Listen_Set; + typedef ACE_Unbounded_Set<LiveListener_ptr> Listen_Set; Listen_Set listeners_; TAO_SYNCH_MUTEX lock_; static const int reping_msec_ []; |