diff options
author | Gerben Stavenga <gerbens@google.com> | 2017-08-02 18:25:28 -0700 |
---|---|---|
committer | Gerben Stavenga <gerbens@google.com> | 2017-08-02 18:25:28 -0700 |
commit | 778178479626b0e5b4de0701103a1bb0a067702d (patch) | |
tree | 2c80366a7fe6389b33764b5895e24d1bb6435971 /src/google/protobuf/compiler/cpp | |
parent | 53ae6de18b51509e67ec84bd6363985d14750bd7 (diff) |
Add destructors for default instances to the shutdown code.
Verified test succeed under draconian heap checker
Diffstat (limited to 'src/google/protobuf/compiler/cpp')
-rw-r--r-- | src/google/protobuf/compiler/cpp/cpp_message.cc | 4 | ||||
-rw-r--r-- | src/google/protobuf/compiler/cpp/cpp_message_field.cc | 6 |
2 files changed, 9 insertions, 1 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"); } |