Commit 5452bd6e authored by Feng Xiao's avatar Feng Xiao

Merge pull request #43 from abuszta/bugfix

Release objects allocated by InitializeDefaultRepeatedFields()
parents 3b8dadf5 e670b670
...@@ -1621,6 +1621,7 @@ PROTOBUF_DEFINE_DEFAULT_REPEATED(bool) ...@@ -1621,6 +1621,7 @@ PROTOBUF_DEFINE_DEFAULT_REPEATED(bool)
struct StaticDefaultRepeatedFieldsInitializer { struct StaticDefaultRepeatedFieldsInitializer {
StaticDefaultRepeatedFieldsInitializer() { StaticDefaultRepeatedFieldsInitializer() {
InitializeDefaultRepeatedFields(); InitializeDefaultRepeatedFields();
OnShutdown(&DestroyDefaultRepeatedFields);
} }
} static_repeated_fields_initializer; } static_repeated_fields_initializer;
...@@ -1645,6 +1646,18 @@ void InitializeDefaultRepeatedFields() { ...@@ -1645,6 +1646,18 @@ void InitializeDefaultRepeatedFields() {
new RepeatedField<bool>; new RepeatedField<bool>;
} }
void DestroyDefaultRepeatedFields() {
delete RepeatedStringTypeTraits::default_repeated_field_;
delete RepeatedMessageGenericTypeTraits::default_repeated_field_;
delete RepeatedPrimitiveGenericTypeTraits::default_repeated_field_int32_;
delete RepeatedPrimitiveGenericTypeTraits::default_repeated_field_int64_;
delete RepeatedPrimitiveGenericTypeTraits::default_repeated_field_uint32_;
delete RepeatedPrimitiveGenericTypeTraits::default_repeated_field_uint64_;
delete RepeatedPrimitiveGenericTypeTraits::default_repeated_field_double_;
delete RepeatedPrimitiveGenericTypeTraits::default_repeated_field_float_;
delete RepeatedPrimitiveGenericTypeTraits::default_repeated_field_bool_;
}
} // namespace internal } // namespace internal
} // namespace protobuf } // namespace protobuf
} // namespace google } // namespace google
...@@ -704,11 +704,13 @@ class RepeatedPrimitiveTypeTraits { ...@@ -704,11 +704,13 @@ class RepeatedPrimitiveTypeTraits {
// Declared here so that this can be friended below. // Declared here so that this can be friended below.
void InitializeDefaultRepeatedFields(); void InitializeDefaultRepeatedFields();
void DestroyDefaultRepeatedFields();
class LIBPROTOBUF_EXPORT RepeatedPrimitiveGenericTypeTraits { class LIBPROTOBUF_EXPORT RepeatedPrimitiveGenericTypeTraits {
private: private:
template<typename Type> friend class RepeatedPrimitiveTypeTraits; template<typename Type> friend class RepeatedPrimitiveTypeTraits;
friend void InitializeDefaultRepeatedFields(); friend void InitializeDefaultRepeatedFields();
friend void DestroyDefaultRepeatedFields();
static const RepeatedField<int32>* default_repeated_field_int32_; static const RepeatedField<int32>* default_repeated_field_int32_;
static const RepeatedField<int64>* default_repeated_field_int64_; static const RepeatedField<int64>* default_repeated_field_int64_;
static const RepeatedField<uint32>* default_repeated_field_uint32_; static const RepeatedField<uint32>* default_repeated_field_uint32_;
...@@ -844,6 +846,7 @@ class LIBPROTOBUF_EXPORT RepeatedStringTypeTraits { ...@@ -844,6 +846,7 @@ class LIBPROTOBUF_EXPORT RepeatedStringTypeTraits {
private: private:
friend void InitializeDefaultRepeatedFields(); friend void InitializeDefaultRepeatedFields();
friend void DestroyDefaultRepeatedFields();
static const RepeatedFieldType *default_repeated_field_; static const RepeatedFieldType *default_repeated_field_;
}; };
...@@ -1010,6 +1013,7 @@ class LIBPROTOBUF_EXPORT RepeatedMessageGenericTypeTraits { ...@@ -1010,6 +1013,7 @@ class LIBPROTOBUF_EXPORT RepeatedMessageGenericTypeTraits {
private: private:
template<typename Type> friend class RepeatedMessageTypeTraits; template<typename Type> friend class RepeatedMessageTypeTraits;
friend void InitializeDefaultRepeatedFields(); friend void InitializeDefaultRepeatedFields();
friend void DestroyDefaultRepeatedFields();
static const RepeatedFieldType* default_repeated_field_; static const RepeatedFieldType* default_repeated_field_;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment