aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/compiler
diff options
context:
space:
mode:
authorGravatar Gerben Stavenga <gerbens@google.com>2017-08-02 18:25:28 -0700
committerGravatar Gerben Stavenga <gerbens@google.com>2017-08-02 18:25:28 -0700
commit778178479626b0e5b4de0701103a1bb0a067702d (patch)
tree2c80366a7fe6389b33764b5895e24d1bb6435971 /src/google/protobuf/compiler
parent53ae6de18b51509e67ec84bd6363985d14750bd7 (diff)
Add destructors for default instances to the shutdown code.
Verified test succeed under draconian heap checker
Diffstat (limited to 'src/google/protobuf/compiler')
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_message.cc4
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_message_field.cc6
-rw-r--r--src/google/protobuf/compiler/plugin.pb.cc14
3 files changed, 18 insertions, 6 deletions
diff --git a/src/google/protobuf/compiler/cpp/cpp_message.cc b/src/google/protobuf/compiler/cpp/cpp_message.cc
index 79d0c633..abb2e95a 100644
--- a/src/google/protobuf/compiler/cpp/cpp_message.cc
+++ b/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_);
}
diff --git a/src/google/protobuf/compiler/cpp/cpp_message_field.cc b/src/google/protobuf/compiler/cpp/cpp_message_field.cc
index 5b260caa..da4c3950 100644
--- a/src/google/protobuf/compiler/cpp/cpp_message_field.cc
+++ b/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");
}
diff --git a/src/google/protobuf/compiler/plugin.pb.cc b/src/google/protobuf/compiler/plugin.pb.cc
index 6753d57d..5d7dad98 100644
--- a/src/google/protobuf/compiler/plugin.pb.cc
+++ b/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 {