diff options
author | coryan <coryan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1998-01-17 05:44:42 +0000 |
---|---|---|
committer | coryan <coryan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1998-01-17 05:44:42 +0000 |
commit | 60e492b1d860118abd0a3f53edc154888b8f42d2 (patch) | |
tree | 457a413b8bc66bf26e9d639cc66064cc3ddd173f /TAO | |
parent | d34aa9f7572ebbe9a251fce23c54fa55045429a8 (diff) | |
download | ATCD-60e492b1d860118abd0a3f53edc154888b8f42d2.tar.gz |
ChangeLogTag:Fri Jan 16 23:38:38 1998 <coryan@MILONGA>
Diffstat (limited to 'TAO')
-rw-r--r-- | TAO/ChangeLog-98c | 13 | ||||
-rw-r--r-- | TAO/tao/decode.cpp | 20 | ||||
-rw-r--r-- | TAO/tao/deep_free.cpp | 181 | ||||
-rw-r--r-- | TAO/tao/giop.h | 4 | ||||
-rw-r--r-- | TAO/tao/iiopobj.cpp | 2 | ||||
-rw-r--r-- | TAO/tao/sequence.h | 3 | ||||
-rw-r--r-- | TAO/tao/sequence_T.cpp | 114 |
7 files changed, 109 insertions, 228 deletions
diff --git a/TAO/ChangeLog-98c b/TAO/ChangeLog-98c index 410341d5ba0..3be7ff01aa4 100644 --- a/TAO/ChangeLog-98c +++ b/TAO/ChangeLog-98c @@ -1,3 +1,16 @@ +Fri Jan 16 23:38:38 1998 <coryan@MILONGA> + + * tao/decode.cpp: + * tao/deep_free.cpp: + * tao/giop.h: + * tao/iiopobj.cpp: + * tao/sequence.h: + * tao/sequence_T.h: + * tao/sequence_T.cpp: + Fixed some memory *deallocation* problems with sequences, they + needed a _deallocate_buffer() method, not to implement the base + class destructor, but to implement deep_free. + Fri Jan 16 18:01:03 1998 Carlos O'Ryan <coryan@cs.wustl.edu> * The Event Service works on Solaris/SunCC again. diff --git a/TAO/tao/decode.cpp b/TAO/tao/decode.cpp index ed9f9ccf6e1..e08592a4d45 100644 --- a/TAO/tao/decode.cpp +++ b/TAO/tao/decode.cpp @@ -954,17 +954,19 @@ TAO_Marshal_String::decode (CORBA::TypeCode_ptr, // but we will accept them when it's clear how to do so. continue_decoding = stream->get_ulong (len); - // note that the encoded length is 1 more than the length of the string - // because it also accounts for the terminating NULL character - str = (*(char **) data) = CORBA::string_alloc (len - 1); - if (len != 0) { - while (continue_decoding != CORBA::B_FALSE && len-- != 0) - { - continue_decoding = stream->get_char (*(CORBA::Char *) str); - str++; - } + // note that the encoded length is 1 more than the length of the string + // because it also accounts for the terminating NULL character + + str = (*(char **) data) = CORBA::string_alloc (len - 1); + // only allocate the string *after* the length was validated. + + while (continue_decoding != CORBA::B_FALSE && len-- != 0) + { + continue_decoding = stream->get_char (*(CORBA::Char *) str); + str++; + } } if (continue_decoding == CORBA::B_TRUE) return CORBA::TypeCode::TRAVERSE_CONTINUE; diff --git a/TAO/tao/deep_free.cpp b/TAO/tao/deep_free.cpp index b6380a69bba..f9a587c69d8 100644 --- a/TAO/tao/deep_free.cpp +++ b/TAO/tao/deep_free.cpp @@ -436,184 +436,19 @@ CORBA::TypeCode::traverse_status TAO_Marshal_Sequence::deep_free (CORBA::TypeCode_ptr tc, const void *source, const void *dest, - CORBA::Environment &env) -{ - CORBA::TypeCode::traverse_status retval = - CORBA::TypeCode::TRAVERSE_CONTINUE; // return status - CORBA::TypeCode_ptr tc2; // typecode of the element - size_t size; // size of element - CORBA::ULong bounds; - char *value1; - CORBA::OctetSeq *src; - CDR stream; // used only to access the marshal_object factory - - // Rely on binary format of sequences -- all are the same - // except for the type pointed to by "buffer" + CORBA::Environment &env){ + // TAO implements sequences using inheritance from a base + // class. That class allocate and deallocates the buffer, using + // virtual methods. if (tc) { - src = (CORBA::OctetSeq *) source; - - // get element typecode - tc2 = tc->content_type (env); - if (env.exception () == 0) - { - // get the size of the element - size = tc2->size (env); - if (env.exception () == 0) - { - // compute the length of the sequence - bounds = src->length; + TAO_Base_Sequence *src = ACE_reinterpret_cast(TAO_Base_Sequence*,source); - value1 = (char *)src->buffer; - switch (tc2->kind_) - { - case CORBA::tk_null: - case CORBA::tk_void: - case CORBA::tk_short: - case CORBA::tk_ushort: - case CORBA::tk_long: - case CORBA::tk_ulong: - case CORBA::tk_float: - case CORBA::tk_double: - case CORBA::tk_longlong: - case CORBA::tk_ulonglong: - case CORBA::tk_boolean: - case CORBA::tk_char: - case CORBA::tk_octet: - case CORBA::tk_longdouble: - case CORBA::tk_wchar: - case CORBA::tk_enum: - delete [] src->buffer; - // CORBA::release (tc2); - return CORBA::TypeCode::TRAVERSE_CONTINUE; - - // handle all aggregate types here - case CORBA::tk_any: - while (bounds-- && retval == CORBA::TypeCode::TRAVERSE_CONTINUE) - { - retval = TAO_Marshal_Any::deep_free (tc2, value1, dest, env); - value1 = (char *)value1 + size; - } - break; - case CORBA::tk_TypeCode: - while (bounds-- && retval == CORBA::TypeCode::TRAVERSE_CONTINUE) - { - retval = TAO_Marshal_TypeCode::deep_free (tc2, value1, dest, env); - value1 = (char *)value1 + size; - } - break; - case CORBA::tk_Principal: - while (bounds-- && retval == CORBA::TypeCode::TRAVERSE_CONTINUE) - { - retval = TAO_Marshal_Principal::deep_free (tc2, value1, dest, env); - value1 = (char *)value1 + size; - } - break; - case CORBA::tk_objref: - while (bounds-- && retval == CORBA::TypeCode::TRAVERSE_CONTINUE) - { - retval = TAO_Marshal_ObjRef::deep_free (tc2, value1, dest, env); - value1 = (char *)value1 + size; - } - break; - case CORBA::tk_struct: - while (bounds-- && retval == CORBA::TypeCode::TRAVERSE_CONTINUE) - { - retval = TAO_Marshal_Struct::deep_free (tc2, value1, dest, env); - value1 = (char *)value1 + size; - } - break; - case CORBA::tk_union: - while (bounds-- && retval == CORBA::TypeCode::TRAVERSE_CONTINUE) - { - retval = TAO_Marshal_Union::deep_free (tc2, value1, dest, env); - value1 = (char *)value1 + size; - } - break; - case CORBA::tk_string: - while (bounds-- && retval == CORBA::TypeCode::TRAVERSE_CONTINUE) - { - retval = TAO_Marshal_String::deep_free (tc2, (char **)value1, dest, env); - value1 = (char *)value1 + size; - } - break; - case CORBA::tk_sequence: - while (bounds-- && retval == CORBA::TypeCode::TRAVERSE_CONTINUE) - { - retval = TAO_Marshal_Sequence::deep_free (tc2, value1, dest, env); - value1 = (char *)value1 + size; - } - break; - case CORBA::tk_array: - while (bounds-- && retval == CORBA::TypeCode::TRAVERSE_CONTINUE) - { - retval = TAO_Marshal_Array::deep_free (tc2, value1, dest, env); - value1 = (char *)value1 + size; - } - break; - case CORBA::tk_alias: - while (bounds-- && retval == CORBA::TypeCode::TRAVERSE_CONTINUE) - { - retval = TAO_Marshal_Alias::deep_free (tc2, value1, dest, env); - value1 = (char *)value1 + size; - } - break; - case CORBA::tk_except: - while (bounds-- && retval == CORBA::TypeCode::TRAVERSE_CONTINUE) - { - retval = TAO_Marshal_Except::deep_free (tc2, value1, dest, env); - value1 = (char *)value1 + size; - } - break; - case CORBA::tk_wstring: - while (bounds-- && retval == CORBA::TypeCode::TRAVERSE_CONTINUE) - { - retval = TAO_Marshal_WString::deep_free (tc2, value1, dest, env); - value1 = (char *)value1 + size; - } - break; - default: - retval = CORBA::TypeCode::TRAVERSE_STOP; - break; - } // end of switch - if (retval == CORBA::TypeCode::TRAVERSE_CONTINUE) - { - // CORBA::release (tc2); - // XXXASG - need to release the typecode - // deallocate the top level buffer - delete [] src->buffer; - return CORBA::TypeCode::TRAVERSE_CONTINUE; - } - else - { - // error exit - env.exception (new CORBA::MARSHAL (CORBA::COMPLETED_NO)); - dmsg ("marshaling TAO_Marshal_Sequence::deep_free detected error"); - return CORBA::TypeCode::TRAVERSE_STOP; - } - } - else // exception computing size - { - // CORBA::release (tc2); - env.exception (new CORBA::BAD_TYPECODE (CORBA::COMPLETED_MAYBE)); - dmsg ("marshaling TAO_Marshal_Sequence::deep_free detected error"); - return CORBA::TypeCode::TRAVERSE_STOP; - } - } - else // exception computing content type - { - env.exception (new CORBA::BAD_TYPECODE (CORBA::COMPLETED_MAYBE)); - dmsg ("marshaling TAO_Marshal_Sequence::deep_free detected error"); - return CORBA::TypeCode::TRAVERSE_STOP; - } - } - else // no typecode - { - env.exception (new CORBA::BAD_TYPECODE (CORBA::COMPLETED_MAYBE)); - dmsg ("TAO_Marshal_Struct::deep_free detected error"); - return CORBA::TypeCode::TRAVERSE_STOP; + src->_deallocate_buffer (); + return CORBA::TypeCode::TRAVERSE_CONTINUE; } + return CORBA::TypeCode::TRAVERSE_STOP; } // deep_free for Array diff --git a/TAO/tao/giop.h b/TAO/tao/giop.h index 4bef3b193bb..99bb59f0cce 100644 --- a/TAO/tao/giop.h +++ b/TAO/tao/giop.h @@ -154,6 +154,10 @@ struct TAO_GIOP_MessageHeader }; // defined by GIOP 1.0 protocol +// @@ Is this portable? The structure above could have some padding on +// machines with absurd padding requirements (like 8 byte boundaries); +// hence the size of it may not match th size of the header on the +// wire. #define TAO_GIOP_HEADER_LEN sizeof (TAO_GIOP_MessageHeader) // Support for Implicit ORB Service Context diff --git a/TAO/tao/iiopobj.cpp b/TAO/tao/iiopobj.cpp index 90d340d0381..f60c3b98e39 100644 --- a/TAO/tao/iiopobj.cpp +++ b/TAO/tao/iiopobj.cpp @@ -58,7 +58,7 @@ IIOP::Profile::set (const char *h, key = buffer; } - this->object_key.length (ACE_OS::strlen (key)); + this->object_key.length (ACE_OS::strlen (key) + 1); for (CORBA::ULong i = 0; i < this->object_key.length (); diff --git a/TAO/tao/sequence.h b/TAO/tao/sequence.h index b067dd039cb..ca9f24a069f 100644 --- a/TAO/tao/sequence.h +++ b/TAO/tao/sequence.h @@ -48,6 +48,9 @@ public: // operator= and then their destructors must be called. // Finally the old buffer must be released. + virtual void _deallocate_buffer (void) = 0; + // Must deallocate the buffer and then set it to zero. + protected: TAO_Base_Sequence (void); // Default constructor. diff --git a/TAO/tao/sequence_T.cpp b/TAO/tao/sequence_T.cpp index 4f276dd7cf4..201bcd5f371 100644 --- a/TAO/tao/sequence_T.cpp +++ b/TAO/tao/sequence_T.cpp @@ -50,11 +50,7 @@ TAO_Unbounded_Sequence<T>::operator= template<class T> TAO_Unbounded_Sequence<T>::~TAO_Unbounded_Sequence (void) { - if (this->buffer_ == 0 || this->release_ == 0) - return; - T* tmp = ACE_reinterpret_cast (T*,this->buffer_); - delete[] tmp; - this->buffer_ = 0; + this->_deallocate_buffer (); } template<class T> @@ -75,6 +71,16 @@ void TAO_Unbounded_Sequence<T>::_allocate_buffer (CORBA::ULong length) this->buffer_ = tmp; } +template<class T> +void TAO_Unbounded_Sequence<T>::_deallocate_buffer (void) +{ + if (this->buffer_ == 0 || this->release_ == 0) + return; + T* tmp = ACE_reinterpret_cast (T*,this->buffer_); + delete[] tmp; + this->buffer_ = 0; +} + // **************************************************************** // Bounded_Sequence // **************************************************************** @@ -108,11 +114,7 @@ TAO_Bounded_Sequence<T,MAX>::operator= (const TAO_Bounded_Sequence<T,MAX> &rhs) template<class T, CORBA::ULong MAX> TAO_Bounded_Sequence<T,MAX>::~TAO_Bounded_Sequence (void) { - if (this->buffer_ == 0 || this->release_ == 0) - return; - T* tmp = ACE_reinterpret_cast (T*,this->buffer_); - delete[] tmp; - this->buffer_ = 0; + this->_deallocate_buffer (); } template<class T, CORBA::ULong MAX> @@ -124,6 +126,16 @@ void TAO_Bounded_Sequence<T,MAX>::_allocate_buffer (CORBA::ULong) this->maximum_ = MAX; } +template<class T, CORBA::ULong MAX> +void TAO_Bounded_Sequence<T,MAX>::_deallocate_buffer (void) +{ + if (this->buffer_ == 0 || this->release_ == 0) + return; + T* tmp = ACE_reinterpret_cast (T*,this->buffer_); + delete[] tmp; + this->buffer_ = 0; +} + // ************************************************************* // class TAO_Object_Manager // ************************************************************* @@ -188,33 +200,9 @@ TAO_Object_Manager<T>::_retn (void) // ************************************************************* template<class T, class Manager> -void TAO_Unbounded_Managed_Sequence<T,Manager>::_allocate_buffer (CORBA::ULong length) -{ - T* *tmp; - ACE_NEW (tmp, T* [length]); - - if (this->buffer_ != 0) - { - T* *old = ACE_reinterpret_cast(T**,this->buffer_); - for (CORBA::ULong i = 0; i < this->length_; ++i) - { - tmp [i] = T::_duplicate (old[i]); - } - delete[] old; - } - this->buffer_ = tmp; -} - -template<class T, class Manager> TAO_Unbounded_Managed_Sequence<T,Manager>::~TAO_Unbounded_Managed_Sequence (void) { - if (this->buffer_ == 0 || this->release_ == 0) - return; - T* *tmp = ACE_reinterpret_cast (T**,this->buffer_); - // XXXASG: Do we release each object here? - // @@ TODO add static methods to Manager to release each object. - delete[] tmp; - this->buffer_ = 0; + this->_deallocate_buffer (); } // copy constructor @@ -270,12 +258,8 @@ TAO_Unbounded_Managed_Sequence<T,Manager>::freebuf (T* *seq, TAO_Unbounded_Managed_Sequence<T,Manager>::freebuf (seq); } -// ************************************************************* -// Operations for class TAO_Bounded_Managed_Sequence -// ************************************************************* - -template<class T, class Manager, CORBA::ULong MAX> void -TAO_Bounded_Managed_Sequence<T,Manager,MAX>::_allocate_buffer (CORBA::ULong length) +template<class T, class Manager> +void TAO_Unbounded_Managed_Sequence<T,Manager>::_allocate_buffer (CORBA::ULong length) { T* *tmp; ACE_NEW (tmp, T* [length]); @@ -292,18 +276,28 @@ TAO_Bounded_Managed_Sequence<T,Manager,MAX>::_allocate_buffer (CORBA::ULong leng this->buffer_ = tmp; } -template<class T, class Manager, CORBA::ULong MAX> -TAO_Bounded_Managed_Sequence<T,Manager,MAX>::~TAO_Bounded_Managed_Sequence (void) +template<class T, class Manager> +void TAO_Unbounded_Managed_Sequence<T,Manager>::_deallocate_buffer (void) { if (this->buffer_ == 0 || this->release_ == 0) return; T* *tmp = ACE_reinterpret_cast (T**,this->buffer_); // XXXASG: Do we release each object here? - // @@ TODO add static methods to Manager to release each object here. + // @@ TODO add static methods to Manager to release each object. delete[] tmp; this->buffer_ = 0; } +// ************************************************************* +// Operations for class TAO_Bounded_Managed_Sequence +// ************************************************************* + +template<class T, class Manager, CORBA::ULong MAX> +TAO_Bounded_Managed_Sequence<T,Manager,MAX>::~TAO_Bounded_Managed_Sequence (void) +{ + this->_deallocate_buffer (); +} + // copy constructor template <class T, class Manager, CORBA::ULong MAX> TAO_Bounded_Managed_Sequence<T,Manager,MAX>::TAO_Bounded_Managed_Sequence @@ -349,7 +343,7 @@ TAO_Bounded_Managed_Sequence<T,Manager,MAX>::allocbuf (CORBA::ULong nelems) template <class T, class Manager, CORBA::ULong MAX> void TAO_Bounded_Managed_Sequence<T,Manager,MAX>::freebuf (T* *seq, - CORBA::ULong nelems) + CORBA::ULong nelems) { if (!seq) return; // null sequence for (CORBA::ULong i=0; i < nelems; i++) @@ -357,4 +351,34 @@ TAO_Bounded_Managed_Sequence<T,Manager,MAX>::freebuf (T* *seq, TAO_Bounded_Managed_Sequence<T,Manager,MAX>::freebuf (seq); } +template<class T, class Manager, CORBA::ULong MAX> void +TAO_Bounded_Managed_Sequence<T,Manager,MAX>::_allocate_buffer (CORBA::ULong length) +{ + T* *tmp; + ACE_NEW (tmp, T* [length]); + + if (this->buffer_ != 0) + { + T* *old = ACE_reinterpret_cast(T**,this->buffer_); + for (CORBA::ULong i = 0; i < this->length_; ++i) + { + tmp [i] = T::_duplicate (old[i]); + } + delete[] old; + } + this->buffer_ = tmp; +} + +template<class T, class Manager, CORBA::ULong MAX> +void TAO_Bounded_Managed_Sequence<T,Manager,MAX>::_deallocate_buffer (void) +{ + if (this->buffer_ == 0 || this->release_ == 0) + return; + T* *tmp = ACE_reinterpret_cast (T**,this->buffer_); + // XXXASG: Do we release each object here? + // @@ TODO add static methods to Manager to release each object here. + delete[] tmp; + this->buffer_ = 0; +} + #endif /* TAO_SEQUENCE_T_C */ |