Selaa lähdekoodia

Add destructors for default instances to the shutdown code.
Verified test succeed under draconian heap checker

Gerben Stavenga 8 vuotta sitten
vanhempi
commit
7781784796

+ 2 - 1
src/google/protobuf/any.pb.cc

@@ -89,7 +89,8 @@ void TableStruct::InitDefaultsImpl() {
 
   ::google::protobuf::internal::InitProtobufDefaults();
   _Any_default_instance_.DefaultConstruct();
-}
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_Any_default_instance_);}
 
 void InitDefaults() {
   static GOOGLE_PROTOBUF_DECLARE_ONCE(once);

+ 7 - 4
src/google/protobuf/api.pb.cc

@@ -125,9 +125,12 @@ void TableStruct::InitDefaultsImpl() {
   ::google::protobuf::protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto::InitDefaults();
   ::google::protobuf::protobuf_google_2fprotobuf_2ftype_2eproto::InitDefaults();
   _Api_default_instance_.DefaultConstruct();
-  _Method_default_instance_.DefaultConstruct();
-  _Mixin_default_instance_.DefaultConstruct();
-  _Api_default_instance_.get_mutable()->source_context_ = const_cast< ::google::protobuf::SourceContext*>(
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_Api_default_instance_);_Method_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_Method_default_instance_);_Mixin_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_Mixin_default_instance_);_Api_default_instance_.get_mutable()->source_context_ = const_cast< ::google::protobuf::SourceContext*>(
       ::google::protobuf::SourceContext::internal_default_instance());
 }
 
@@ -244,7 +247,7 @@ Api::~Api() {
 void Api::SharedDtor() {
   name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
   version_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
-  delete source_context_;
+  if (this != internal_default_instance()) delete source_context_;
 }
 
 void Api::SetCachedSize(int size) const {

+ 3 - 1
src/google/protobuf/compiler/cpp/cpp_message.cc

@@ -1977,7 +1977,9 @@ GenerateDefaultInstanceAllocator(io::Printer* printer) {
   // Construct the default instance.  We can't call InitAsDefaultInstance() yet
   // because we need to make sure all default instances that this one might
   // depend on are constructed first.
-  printer->Print("_$classname$_default_instance_.DefaultConstruct();\n",
+  printer->Print("_$classname$_default_instance_.DefaultConstruct();\n"
+                 "::google::protobuf::internal::OnShutdownDestroyMessage(\n"
+                 "    &_$classname$_default_instance_);",
                  "classname", classname_);
 }
 

+ 6 - 0
src/google/protobuf/compiler/cpp/cpp_message_field.cc

@@ -522,6 +522,12 @@ GenerateSwappingCode(io::Printer* printer) const {
 
 void MessageFieldGenerator::
 GenerateDestructorCode(io::Printer* printer) const {
+  // TODO(gerbens) Remove this when we don't need to destruct default instances.
+  // In google3 a default instance will never get deleted so we don't need to
+  // worry about that but in opensource protobuf default instances are deleted
+  // in shutdown process and we need to take special care when handling them.
+  printer->Print(variables_,
+    "if (this != internal_default_instance()) ");
   printer->Print(variables_, "delete $name$_;\n");
 }
 

+ 9 - 5
src/google/protobuf/compiler/plugin.pb.cc

@@ -145,10 +145,14 @@ void TableStruct::InitDefaultsImpl() {
   ::google::protobuf::internal::InitProtobufDefaults();
   ::google::protobuf::protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
   _Version_default_instance_.DefaultConstruct();
-  _CodeGeneratorRequest_default_instance_.DefaultConstruct();
-  _CodeGeneratorResponse_File_default_instance_.DefaultConstruct();
-  _CodeGeneratorResponse_default_instance_.DefaultConstruct();
-  _CodeGeneratorRequest_default_instance_.get_mutable()->compiler_version_ = const_cast< ::google::protobuf::compiler::Version*>(
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_Version_default_instance_);_CodeGeneratorRequest_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_CodeGeneratorRequest_default_instance_);_CodeGeneratorResponse_File_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_CodeGeneratorResponse_File_default_instance_);_CodeGeneratorResponse_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_CodeGeneratorResponse_default_instance_);_CodeGeneratorRequest_default_instance_.get_mutable()->compiler_version_ = const_cast< ::google::protobuf::compiler::Version*>(
       ::google::protobuf::compiler::Version::internal_default_instance());
 }
 
@@ -776,7 +780,7 @@ CodeGeneratorRequest::~CodeGeneratorRequest() {
 
 void CodeGeneratorRequest::SharedDtor() {
   parameter_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
-  delete compiler_version_;
+  if (this != internal_default_instance()) delete compiler_version_;
 }
 
 void CodeGeneratorRequest::SetCachedSize(int size) const {

+ 62 - 36
src/google/protobuf/descriptor.pb.cc

@@ -574,32 +574,58 @@ void TableStruct::InitDefaultsImpl() {
 
   ::google::protobuf::internal::InitProtobufDefaults();
   _FileDescriptorSet_default_instance_.DefaultConstruct();
-  _FileDescriptorProto_default_instance_.DefaultConstruct();
-  _DescriptorProto_ExtensionRange_default_instance_.DefaultConstruct();
-  _DescriptorProto_ReservedRange_default_instance_.DefaultConstruct();
-  _DescriptorProto_default_instance_.DefaultConstruct();
-  _ExtensionRangeOptions_default_instance_.DefaultConstruct();
-  _FieldDescriptorProto_default_instance_.DefaultConstruct();
-  _OneofDescriptorProto_default_instance_.DefaultConstruct();
-  _EnumDescriptorProto_default_instance_.DefaultConstruct();
-  _EnumValueDescriptorProto_default_instance_.DefaultConstruct();
-  _ServiceDescriptorProto_default_instance_.DefaultConstruct();
-  _MethodDescriptorProto_default_instance_.DefaultConstruct();
-  _FileOptions_default_instance_.DefaultConstruct();
-  _MessageOptions_default_instance_.DefaultConstruct();
-  _FieldOptions_default_instance_.DefaultConstruct();
-  _OneofOptions_default_instance_.DefaultConstruct();
-  _EnumOptions_default_instance_.DefaultConstruct();
-  _EnumValueOptions_default_instance_.DefaultConstruct();
-  _ServiceOptions_default_instance_.DefaultConstruct();
-  _MethodOptions_default_instance_.DefaultConstruct();
-  _UninterpretedOption_NamePart_default_instance_.DefaultConstruct();
-  _UninterpretedOption_default_instance_.DefaultConstruct();
-  _SourceCodeInfo_Location_default_instance_.DefaultConstruct();
-  _SourceCodeInfo_default_instance_.DefaultConstruct();
-  _GeneratedCodeInfo_Annotation_default_instance_.DefaultConstruct();
-  _GeneratedCodeInfo_default_instance_.DefaultConstruct();
-  _FileDescriptorProto_default_instance_.get_mutable()->options_ = const_cast< ::google::protobuf::FileOptions*>(
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_FileDescriptorSet_default_instance_);_FileDescriptorProto_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_FileDescriptorProto_default_instance_);_DescriptorProto_ExtensionRange_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_DescriptorProto_ExtensionRange_default_instance_);_DescriptorProto_ReservedRange_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_DescriptorProto_ReservedRange_default_instance_);_DescriptorProto_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_DescriptorProto_default_instance_);_ExtensionRangeOptions_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_ExtensionRangeOptions_default_instance_);_FieldDescriptorProto_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_FieldDescriptorProto_default_instance_);_OneofDescriptorProto_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_OneofDescriptorProto_default_instance_);_EnumDescriptorProto_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_EnumDescriptorProto_default_instance_);_EnumValueDescriptorProto_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_EnumValueDescriptorProto_default_instance_);_ServiceDescriptorProto_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_ServiceDescriptorProto_default_instance_);_MethodDescriptorProto_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_MethodDescriptorProto_default_instance_);_FileOptions_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_FileOptions_default_instance_);_MessageOptions_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_MessageOptions_default_instance_);_FieldOptions_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_FieldOptions_default_instance_);_OneofOptions_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_OneofOptions_default_instance_);_EnumOptions_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_EnumOptions_default_instance_);_EnumValueOptions_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_EnumValueOptions_default_instance_);_ServiceOptions_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_ServiceOptions_default_instance_);_MethodOptions_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_MethodOptions_default_instance_);_UninterpretedOption_NamePart_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_UninterpretedOption_NamePart_default_instance_);_UninterpretedOption_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_UninterpretedOption_default_instance_);_SourceCodeInfo_Location_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_SourceCodeInfo_Location_default_instance_);_SourceCodeInfo_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_SourceCodeInfo_default_instance_);_GeneratedCodeInfo_Annotation_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_GeneratedCodeInfo_Annotation_default_instance_);_GeneratedCodeInfo_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_GeneratedCodeInfo_default_instance_);_FileDescriptorProto_default_instance_.get_mutable()->options_ = const_cast< ::google::protobuf::FileOptions*>(
       ::google::protobuf::FileOptions::internal_default_instance());
   _FileDescriptorProto_default_instance_.get_mutable()->source_code_info_ = const_cast< ::google::protobuf::SourceCodeInfo*>(
       ::google::protobuf::SourceCodeInfo::internal_default_instance());
@@ -1325,8 +1351,8 @@ void FileDescriptorProto::SharedDtor() {
   name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
   package_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
   syntax_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
-  delete options_;
-  delete source_code_info_;
+  if (this != internal_default_instance()) delete options_;
+  if (this != internal_default_instance()) delete source_code_info_;
 }
 
 void FileDescriptorProto::SetCachedSize(int size) const {
@@ -2625,7 +2651,7 @@ DescriptorProto_ExtensionRange::~DescriptorProto_ExtensionRange() {
 }
 
 void DescriptorProto_ExtensionRange::SharedDtor() {
-  delete options_;
+  if (this != internal_default_instance()) delete options_;
 }
 
 void DescriptorProto_ExtensionRange::SetCachedSize(int size) const {
@@ -3425,7 +3451,7 @@ DescriptorProto::~DescriptorProto() {
 
 void DescriptorProto::SharedDtor() {
   name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
-  delete options_;
+  if (this != internal_default_instance()) delete options_;
 }
 
 void DescriptorProto::SetCachedSize(int size) const {
@@ -4820,7 +4846,7 @@ void FieldDescriptorProto::SharedDtor() {
   type_name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
   default_value_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
   json_name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
-  delete options_;
+  if (this != internal_default_instance()) delete options_;
 }
 
 void FieldDescriptorProto::SetCachedSize(int size) const {
@@ -5985,7 +6011,7 @@ OneofDescriptorProto::~OneofDescriptorProto() {
 
 void OneofDescriptorProto::SharedDtor() {
   name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
-  delete options_;
+  if (this != internal_default_instance()) delete options_;
 }
 
 void OneofDescriptorProto::SetCachedSize(int size) const {
@@ -6421,7 +6447,7 @@ EnumDescriptorProto::~EnumDescriptorProto() {
 
 void EnumDescriptorProto::SharedDtor() {
   name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
-  delete options_;
+  if (this != internal_default_instance()) delete options_;
 }
 
 void EnumDescriptorProto::SetCachedSize(int size) const {
@@ -6931,7 +6957,7 @@ EnumValueDescriptorProto::~EnumValueDescriptorProto() {
 
 void EnumValueDescriptorProto::SharedDtor() {
   name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
-  delete options_;
+  if (this != internal_default_instance()) delete options_;
 }
 
 void EnumValueDescriptorProto::SetCachedSize(int size) const {
@@ -7428,7 +7454,7 @@ ServiceDescriptorProto::~ServiceDescriptorProto() {
 
 void ServiceDescriptorProto::SharedDtor() {
   name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
-  delete options_;
+  if (this != internal_default_instance()) delete options_;
 }
 
 void ServiceDescriptorProto::SetCachedSize(int size) const {
@@ -7955,7 +7981,7 @@ void MethodDescriptorProto::SharedDtor() {
   name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
   input_type_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
   output_type_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
-  delete options_;
+  if (this != internal_default_instance()) delete options_;
 }
 
 void MethodDescriptorProto::SetCachedSize(int size) const {

+ 2 - 1
src/google/protobuf/duration.pb.cc

@@ -89,7 +89,8 @@ void TableStruct::InitDefaultsImpl() {
 
   ::google::protobuf::internal::InitProtobufDefaults();
   _Duration_default_instance_.DefaultConstruct();
-}
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_Duration_default_instance_);}
 
 void InitDefaults() {
   static GOOGLE_PROTOBUF_DECLARE_ONCE(once);

+ 2 - 1
src/google/protobuf/empty.pb.cc

@@ -87,7 +87,8 @@ void TableStruct::InitDefaultsImpl() {
 
   ::google::protobuf::internal::InitProtobufDefaults();
   _Empty_default_instance_.DefaultConstruct();
-}
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_Empty_default_instance_);}
 
 void InitDefaults() {
   static GOOGLE_PROTOBUF_DECLARE_ONCE(once);

+ 2 - 1
src/google/protobuf/field_mask.pb.cc

@@ -88,7 +88,8 @@ void TableStruct::InitDefaultsImpl() {
 
   ::google::protobuf::internal::InitProtobufDefaults();
   _FieldMask_default_instance_.DefaultConstruct();
-}
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_FieldMask_default_instance_);}
 
 void InitDefaults() {
   static GOOGLE_PROTOBUF_DECLARE_ONCE(once);

+ 2 - 1
src/google/protobuf/source_context.pb.cc

@@ -88,7 +88,8 @@ void TableStruct::InitDefaultsImpl() {
 
   ::google::protobuf::internal::InitProtobufDefaults();
   _SourceContext_default_instance_.DefaultConstruct();
-}
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_SourceContext_default_instance_);}
 
 void InitDefaults() {
   static GOOGLE_PROTOBUF_DECLARE_ONCE(once);

+ 8 - 4
src/google/protobuf/struct.pb.cc

@@ -129,10 +129,14 @@ void TableStruct::InitDefaultsImpl() {
 
   ::google::protobuf::internal::InitProtobufDefaults();
   _Struct_FieldsEntry_default_instance_.DefaultConstruct();
-  _Struct_default_instance_.DefaultConstruct();
-  _Value_default_instance_.DefaultConstruct();
-  _ListValue_default_instance_.DefaultConstruct();
-  _Struct_FieldsEntry_default_instance_.get_mutable()->set_default_instance(_Struct_FieldsEntry_default_instance_.get_mutable());
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_Struct_FieldsEntry_default_instance_);_Struct_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_Struct_default_instance_);_Value_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_Value_default_instance_);_ListValue_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_ListValue_default_instance_);_Struct_FieldsEntry_default_instance_.get_mutable()->set_default_instance(_Struct_FieldsEntry_default_instance_.get_mutable());
   _Struct_FieldsEntry_default_instance_.get_mutable()->InitAsDefaultInstance();
   _Value_default_instance_.null_value_ = 0;
   _Value_default_instance_.number_value_ = 0;

+ 11 - 0
src/google/protobuf/stubs/common.cc

@@ -30,6 +30,7 @@
 
 // Author: kenton@google.com (Kenton Varda)
 
+#include <google/protobuf/message_lite.h>  // TODO(gerbens) ideally remove this.
 #include <google/protobuf/stubs/common.h>
 #include <google/protobuf/stubs/once.h>
 #include <google/protobuf/stubs/status.h>
@@ -424,10 +425,14 @@ struct ShutdownData {
     for (int i = 0; i < strings.size(); i++) {
       strings[i]->~string();
     }
+    for (int i = 0; i < messages.size(); i++) {
+      messages[i]->~MessageLite();
+    }
   }
 
   vector<void (*)()> functions;
   vector<const std::string*> strings;
+  vector<const MessageLite*> messages;
   Mutex mutex;
 };
 
@@ -454,6 +459,12 @@ void OnShutdownDestroyString(const std::string* ptr) {
   shutdown_data->strings.push_back(ptr);
 }
 
+void OnShutdownDestroyMessage(const void* ptr) {
+  InitShutdownFunctionsOnce();
+  MutexLock lock(&shutdown_data->mutex);
+  shutdown_data->messages.push_back(static_cast<const MessageLite*>(ptr));
+}
+
 }  // namespace internal
 
 void ShutdownProtobufLibrary() {

+ 3 - 0
src/google/protobuf/stubs/common.h

@@ -202,6 +202,9 @@ namespace internal {
 LIBPROTOBUF_EXPORT void OnShutdown(void (*func)());
 // Destroy the string (call string destructor)
 LIBPROTOBUF_EXPORT void OnShutdownDestroyString(const std::string* ptr);
+// Destroy (not delete) the message
+LIBPROTOBUF_EXPORT void OnShutdownDestroyMessage(const void* ptr);
+
 }  // namespace internal
 
 #if PROTOBUF_USE_EXCEPTIONS

+ 2 - 1
src/google/protobuf/timestamp.pb.cc

@@ -89,7 +89,8 @@ void TableStruct::InitDefaultsImpl() {
 
   ::google::protobuf::internal::InitProtobufDefaults();
   _Timestamp_default_instance_.DefaultConstruct();
-}
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_Timestamp_default_instance_);}
 
 void InitDefaults() {
   static GOOGLE_PROTOBUF_DECLARE_ONCE(once);

+ 13 - 8
src/google/protobuf/type.pb.cc

@@ -156,11 +156,16 @@ void TableStruct::InitDefaultsImpl() {
   ::google::protobuf::protobuf_google_2fprotobuf_2fany_2eproto::InitDefaults();
   ::google::protobuf::protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto::InitDefaults();
   _Type_default_instance_.DefaultConstruct();
-  _Field_default_instance_.DefaultConstruct();
-  _Enum_default_instance_.DefaultConstruct();
-  _EnumValue_default_instance_.DefaultConstruct();
-  _Option_default_instance_.DefaultConstruct();
-  _Type_default_instance_.get_mutable()->source_context_ = const_cast< ::google::protobuf::SourceContext*>(
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_Type_default_instance_);_Field_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_Field_default_instance_);_Enum_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_Enum_default_instance_);_EnumValue_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_EnumValue_default_instance_);_Option_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_Option_default_instance_);_Type_default_instance_.get_mutable()->source_context_ = const_cast< ::google::protobuf::SourceContext*>(
       ::google::protobuf::SourceContext::internal_default_instance());
   _Enum_default_instance_.get_mutable()->source_context_ = const_cast< ::google::protobuf::SourceContext*>(
       ::google::protobuf::SourceContext::internal_default_instance());
@@ -440,7 +445,7 @@ void Type::SharedDtor() {
   }
 
   name_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena);
-  delete source_context_;
+  if (this != internal_default_instance()) delete source_context_;
 }
 
 void Type::ArenaDtor(void* object) {
@@ -2353,7 +2358,7 @@ void Enum::SharedDtor() {
   }
 
   name_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena);
-  delete source_context_;
+  if (this != internal_default_instance()) delete source_context_;
 }
 
 void Enum::ArenaDtor(void* object) {
@@ -3535,7 +3540,7 @@ void Option::SharedDtor() {
   }
 
   name_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena);
-  delete value_;
+  if (this != internal_default_instance()) delete value_;
 }
 
 void Option::ArenaDtor(void* object) {

+ 18 - 9
src/google/protobuf/wrappers.pb.cc

@@ -176,15 +176,24 @@ void TableStruct::InitDefaultsImpl() {
 
   ::google::protobuf::internal::InitProtobufDefaults();
   _DoubleValue_default_instance_.DefaultConstruct();
-  _FloatValue_default_instance_.DefaultConstruct();
-  _Int64Value_default_instance_.DefaultConstruct();
-  _UInt64Value_default_instance_.DefaultConstruct();
-  _Int32Value_default_instance_.DefaultConstruct();
-  _UInt32Value_default_instance_.DefaultConstruct();
-  _BoolValue_default_instance_.DefaultConstruct();
-  _StringValue_default_instance_.DefaultConstruct();
-  _BytesValue_default_instance_.DefaultConstruct();
-}
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_DoubleValue_default_instance_);_FloatValue_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_FloatValue_default_instance_);_Int64Value_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_Int64Value_default_instance_);_UInt64Value_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_UInt64Value_default_instance_);_Int32Value_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_Int32Value_default_instance_);_UInt32Value_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_UInt32Value_default_instance_);_BoolValue_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_BoolValue_default_instance_);_StringValue_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_StringValue_default_instance_);_BytesValue_default_instance_.DefaultConstruct();
+  ::google::protobuf::internal::OnShutdownDestroyMessage(
+      &_BytesValue_default_instance_);}
 
 void InitDefaults() {
   static GOOGLE_PROTOBUF_DECLARE_ONCE(once);