Delete some globals in ShutdownProtobufLibrary().

pull/130/head
Feng Xiao 10 years ago
parent 35ef68056c
commit 137dd0f17f
  1. 5
      src/google/protobuf/descriptor.cc
  2. 5
      src/google/protobuf/map_entry.h
  3. 27
      src/google/protobuf/map_field.cc

@ -345,6 +345,10 @@ typedef hash_map<string, const SourceCodeInfo_Location*> LocationsByPathMap;
set<string>* allowed_proto3_extendees_ = NULL; set<string>* allowed_proto3_extendees_ = NULL;
GOOGLE_PROTOBUF_DECLARE_ONCE(allowed_proto3_extendees_init_); GOOGLE_PROTOBUF_DECLARE_ONCE(allowed_proto3_extendees_init_);
void DeleteAllowedProto3Extendee() {
delete allowed_proto3_extendees_;
}
void InitAllowedProto3Extendee() { void InitAllowedProto3Extendee() {
allowed_proto3_extendees_ = new set<string>; allowed_proto3_extendees_ = new set<string>;
allowed_proto3_extendees_->insert("google.protobuf.FileOptions"); allowed_proto3_extendees_->insert("google.protobuf.FileOptions");
@ -354,6 +358,7 @@ void InitAllowedProto3Extendee() {
allowed_proto3_extendees_->insert("google.protobuf.EnumValueOptions"); allowed_proto3_extendees_->insert("google.protobuf.EnumValueOptions");
allowed_proto3_extendees_->insert("google.protobuf.ServiceOptions"); allowed_proto3_extendees_->insert("google.protobuf.ServiceOptions");
allowed_proto3_extendees_->insert("google.protobuf.MethodOptions"); allowed_proto3_extendees_->insert("google.protobuf.MethodOptions");
google::protobuf::internal::OnShutdown(&DeleteAllowedProto3Extendee);
} }
// Checks whether the extendee type is allowed in proto3. // Checks whether the extendee type is allowed in proto3.

@ -43,6 +43,10 @@ class Arena;
namespace protobuf { namespace protobuf {
namespace internal { namespace internal {
// Register all MapEntry default instances so we can delete them in
// ShutdownProtobufLibrary().
void RegisterMapEntryDefaultInstance(MessageLite* default_instance);
// This is the common base class for MapEntry. It is used by MapFieldBase in // This is the common base class for MapEntry. It is used by MapFieldBase in
// reflection api, in which the static type of key and value is unknown. // reflection api, in which the static type of key and value is unknown.
class LIBPROTOBUF_EXPORT MapEntryBase : public Message { class LIBPROTOBUF_EXPORT MapEntryBase : public Message {
@ -317,6 +321,7 @@ class LIBPROTOBUF_EXPORT MapEntry : public MapEntryBase {
entry->reflection_ = reflection; entry->reflection_ = reflection;
entry->default_instance_ = entry; entry->default_instance_ = entry;
entry->InitAsDefaultInstance(); entry->InitAsDefaultInstance();
RegisterMapEntryDefaultInstance(entry);
return entry; return entry;
} }

@ -30,10 +30,37 @@
#include <google/protobuf/map_field.h> #include <google/protobuf/map_field.h>
#include <vector>
namespace google { namespace google {
namespace protobuf { namespace protobuf {
namespace internal { namespace internal {
ProtobufOnceType map_entry_default_instances_once_;
Mutex* map_entry_default_instances_mutex_;
vector<MessageLite*>* map_entry_default_instances_;
void DeleteMapEntryDefaultInstances() {
for (int i = 0; i < map_entry_default_instances_->size(); ++i) {
delete map_entry_default_instances_->at(i);
}
delete map_entry_default_instances_mutex_;
delete map_entry_default_instances_;
}
void InitMapEntryDefaultInstances() {
map_entry_default_instances_mutex_ = new Mutex();
map_entry_default_instances_ = new vector<MessageLite*>();
OnShutdown(&DeleteMapEntryDefaultInstances);
}
void RegisterMapEntryDefaultInstance(MessageLite* default_instance) {
GoogleOnceInit(&map_entry_default_instances_once_,
&InitMapEntryDefaultInstances);
MutexLock lock(map_entry_default_instances_mutex_);
map_entry_default_instances_->push_back(default_instance);
}
MapFieldBase::~MapFieldBase() { MapFieldBase::~MapFieldBase() {
if (repeated_field_ != NULL) delete repeated_field_; if (repeated_field_ != NULL) delete repeated_field_;
} }

Loading…
Cancel
Save