diff options
author | Steve Huston <shuston@riverace.com> | 2006-08-22 23:07:10 +0000 |
---|---|---|
committer | Steve Huston <shuston@riverace.com> | 2006-08-22 23:07:10 +0000 |
commit | 6c4c7fc10846f0d4f1b7c63aaa5123323ee81e26 (patch) | |
tree | 30ebdd4985fc13f078db12444c313c5602c98720 | |
parent | a03a40385c19531d9e11b07ce578833590db11cf (diff) | |
download | ATCD-6c4c7fc10846f0d4f1b7c63aaa5123323ee81e26.tar.gz |
:ChangeLogTag:Tue Aug 22 22:52:41 UTC 2006 Steve Huston <shuston@riverace.com
-rw-r--r-- | ACE/ChangeLog | 24 | ||||
-rw-r--r-- | ACE/protocols/ace/RMCast/Acknowledge.cpp | 6 | ||||
-rw-r--r-- | ACE/protocols/ace/RMCast/Protocol.h | 62 | ||||
-rw-r--r-- | ACE/protocols/ace/RMCast/Reassemble.cpp | 14 |
4 files changed, 72 insertions, 34 deletions
diff --git a/ACE/ChangeLog b/ACE/ChangeLog index fb6f4e45a4b..bebc2bb4f4d 100644 --- a/ACE/ChangeLog +++ b/ACE/ChangeLog @@ -1,3 +1,27 @@ +Tue Aug 22 22:52:41 UTC 2006 Steve Huston <shuston@riverace.com> + + * protocols/ace/RMCast/Protocol.h: Replaced use of + ACE_Refcounted_Auto_Ptr with ACE_Strong_Bound_Ptr. Code formerly used + ACE_Refcounted_Auto_Ptr::release() with the assumption it had the + same semantics as auto_ptr::release() - stealing the pointer away. + This used to work by accident. The fixed ACE_Refcounted_Auto_Ptr's + release() method decrements the reference count which may cause the + object to be deleted, which is what happened all the time in the + RMCast protocol's clone() methods. Because all the clone() methods + relied on being able to take a more-derived pointer and use it as + a Profile*, changing the refcounted pointer type necessitated + changing the protected clone_() methods to return a naked pointer + rather than a refcounted one. This is acceptable because the naked + pointer is not exposed to class users; the public methods insert + the naked pointer into a ACE_Strong_Bound_Ptr before giving access + to it externally. + + * protocols/ace/RMCast/Acknowledge.cpp: + * protocols/ace/RMCast/Reassemble.cpp: With properly functioning + refcounted pointers (see above) these needed a few changes to + make proper use of the pointers while maintaining correct reference + counts. + Tue Aug 22 21:43:34 UTC 2006 Iliyan Jeliazkov <iliyan@ociweb.com> This change fixes bug#2612. diff --git a/ACE/protocols/ace/RMCast/Acknowledge.cpp b/ACE/protocols/ace/RMCast/Acknowledge.cpp index b647a255dad..d3aeb7630f2 100644 --- a/ACE/protocols/ace/RMCast/Acknowledge.cpp +++ b/ACE/protocols/ace/RMCast/Acknowledge.cpp @@ -120,7 +120,7 @@ namespace ACE_RMCast Profile_ptr nrtm (create_nrtm (max_elem)); - if (nrtm.get ()) + if (!nrtm.null ()) { Message_ptr m (new Message); m->add (nrtm); @@ -179,7 +179,7 @@ namespace ACE_RMCast // while (i != e) { - NAK_ptr nak (new NAK (addr)); + auto_ptr<NAK> nak (new NAK (addr)); // Inner loop that fills NAK profile with up to max_elem elements. // @@ -355,7 +355,7 @@ namespace ACE_RMCast { // Prepare NRTM. // - NRTM_ptr nrtm (new NRTM ()); + auto_ptr<NRTM> nrtm (new NRTM ()); // Gather the information. // diff --git a/ACE/protocols/ace/RMCast/Protocol.h b/ACE/protocols/ace/RMCast/Protocol.h index c0e2797b732..7dfd45702ca 100644 --- a/ACE/protocols/ace/RMCast/Protocol.h +++ b/ACE/protocols/ace/RMCast/Protocol.h @@ -5,7 +5,7 @@ #ifndef ACE_RMCAST_PROTOCOL_H #define ACE_RMCAST_PROTOCOL_H -#include "ace/Refcounted_Auto_Ptr.h" +#include "ace/Bound_Ptr.h" #include "ace/Vector_T.h" #include "ace/Hash_Map_Manager.h" @@ -68,7 +68,7 @@ namespace ACE_RMCast struct Profile; typedef - ACE_Refcounted_Auto_Ptr<Profile, Mutex> + ACE_Strong_Bound_Ptr<Profile, Mutex> Profile_ptr; struct Profile @@ -123,7 +123,8 @@ namespace ACE_RMCast Profile_ptr clone () { - return clone_ (); + Profile_ptr p (clone_ ()); + return p; } protected: @@ -137,7 +138,7 @@ namespace ACE_RMCast { } - virtual Profile_ptr + virtual Profile * clone_ () = 0; private: @@ -240,7 +241,7 @@ namespace ACE_RMCast class Message; typedef - ACE_Refcounted_Auto_Ptr<Message, Mutex> + ACE_Strong_Bound_Ptr<Message, Mutex> Message_ptr; class Message @@ -258,7 +259,8 @@ namespace ACE_RMCast Message_ptr clone () { - return new Message (*this); + Message_ptr cloned (new Message (*this)); + return cloned; } protected: @@ -372,7 +374,7 @@ namespace ACE_RMCast struct From; typedef - ACE_Refcounted_Auto_Ptr<From, Mutex> + ACE_Strong_Bound_Ptr<From, Mutex> From_ptr; struct From : Profile @@ -401,11 +403,11 @@ namespace ACE_RMCast From_ptr clone () { - return From_ptr (static_cast<From*> (clone_ ().release ())); + return From_ptr (dynamic_cast<From *> (clone_ ())); } protected: - virtual Profile_ptr + virtual Profile * clone_ () { return new From (*this); @@ -456,7 +458,7 @@ namespace ACE_RMCast struct To; typedef - ACE_Refcounted_Auto_Ptr<To, Mutex> + ACE_Strong_Bound_Ptr<To, Mutex> To_ptr; struct To : Profile @@ -485,11 +487,11 @@ namespace ACE_RMCast To_ptr clone () { - return To_ptr (static_cast<To*> (clone_ ().release ())); + return To_ptr (dynamic_cast<To *> (clone_ ())); } protected: - virtual Profile_ptr + virtual Profile * clone_ () { return new To (*this); @@ -540,7 +542,7 @@ namespace ACE_RMCast struct Data; typedef - ACE_Refcounted_Auto_Ptr<Data, Mutex> + ACE_Strong_Bound_Ptr<Data, Mutex> Data_ptr; struct Data : Profile @@ -586,11 +588,11 @@ namespace ACE_RMCast Data_ptr clone () { - return Data_ptr (static_cast<Data*> (clone_ ().release ())); + return Data_ptr (dynamic_cast<Data *> (clone_ ())); } protected: - virtual Profile_ptr + virtual Profile * clone_ () { return new Data (*this); @@ -673,7 +675,7 @@ namespace ACE_RMCast struct SN; typedef - ACE_Refcounted_Auto_Ptr<SN, Mutex> + ACE_Strong_Bound_Ptr<SN, Mutex> SN_ptr; struct SN : Profile @@ -696,11 +698,11 @@ namespace ACE_RMCast SN_ptr clone () { - return SN_ptr (static_cast<SN*> (clone_ ().release ())); + return SN_ptr (dynamic_cast<SN *> (clone_ ())); } protected: - virtual Profile_ptr + virtual Profile * clone_ () { return new SN (*this); @@ -743,7 +745,7 @@ namespace ACE_RMCast class NAK; typedef - ACE_Refcounted_Auto_Ptr<NAK, Mutex> + ACE_Strong_Bound_Ptr<NAK, Mutex> NAK_ptr; class NAK : public Profile @@ -799,11 +801,11 @@ namespace ACE_RMCast NAK_ptr clone () { - return NAK_ptr (static_cast<NAK*> (clone_ ().release ())); + return NAK_ptr (dynamic_cast<NAK *> (clone_ ())); } protected: - virtual Profile_ptr + virtual Profile * clone_ () { return new NAK (*this); @@ -939,7 +941,7 @@ namespace ACE_RMCast struct NRTM; typedef - ACE_Refcounted_Auto_Ptr<NRTM, Mutex> + ACE_Strong_Bound_Ptr<NRTM, Mutex> NRTM_ptr; struct NRTM : Profile @@ -984,11 +986,11 @@ namespace ACE_RMCast NRTM_ptr clone () { - return NRTM_ptr (static_cast<NRTM*> (clone_ ().release ())); + return NRTM_ptr (dynamic_cast<NRTM *> (clone_ ())); } protected: - virtual Profile_ptr + virtual Profile * clone_ () { return new NRTM (*this); @@ -1113,7 +1115,7 @@ namespace ACE_RMCast struct NoData; typedef - ACE_Refcounted_Auto_Ptr<NoData, Mutex> + ACE_Strong_Bound_Ptr<NoData, Mutex> NoData_ptr; struct NoData : Profile @@ -1135,11 +1137,11 @@ namespace ACE_RMCast NoData_ptr clone () { - return NoData_ptr (static_cast<NoData*> (clone_ ().release ())); + return NoData_ptr (dynamic_cast<NoData *> (clone_ ())); } protected: - virtual Profile_ptr + virtual Profile * clone_ () { return new NoData (*this); @@ -1169,7 +1171,7 @@ namespace ACE_RMCast struct Part; typedef - ACE_Refcounted_Auto_Ptr<Part, Mutex> + ACE_Strong_Bound_Ptr<Part, Mutex> Part_ptr; struct Part : Profile @@ -1197,11 +1199,11 @@ namespace ACE_RMCast Part_ptr clone () { - return Part_ptr (static_cast<Part*> (clone_ ().release ())); + return Part_ptr (dynamic_cast<Part *> (clone_ ())); } protected: - virtual Profile_ptr + virtual Profile * clone_ () { return new Part (*this); diff --git a/ACE/protocols/ace/RMCast/Reassemble.cpp b/ACE/protocols/ace/RMCast/Reassemble.cpp index 9fa3e0d0167..aa5354a40be 100644 --- a/ACE/protocols/ace/RMCast/Reassemble.cpp +++ b/ACE/protocols/ace/RMCast/Reassemble.cpp @@ -88,7 +88,19 @@ namespace ACE_RMCast new_msg->add (Profile_ptr (new To (to))); new_msg->add (Profile_ptr (new From (from))); - new_msg->add (Profile_ptr (new_data.release ())); + /* + * Heads up... we need to add the new_data to new_msg then + * unbind the entry that maps to new_data, which will decrement + * its reference count. If the bound/refcounted pointer acted + * polymorphically like a regular pointer does, we'd be able to + * just pass new_data to add(Profile_Ptr) and it would work. + * However, Profile_Ptr and Data_Ptr are not compatible, but + * we can use the secret knowledge that both are instances of the + * same template and that the pointers they contain really are + * hierarchically compatible, and do this funky cast to get + * the result we want. + */ + new_msg->add (*(reinterpret_cast<Profile_ptr*> (&new_data))); map_.unbind (from); |