Add shutdown code for several newly introduced leaks;

Disable commandline interface test for heap check tests.

Change-Id: I02aa2ad9704e3c70dcecae8b3b3557b18607d455
changes/31/217031/3
Jisi Liu 10 years ago
parent ff35de3ddd
commit 7a00a1e424
  1. 6
      src/google/protobuf/compiler/command_line_interface_unittest.cc
  2. 6
      src/google/protobuf/generated_message_reflection.cc
  3. 24
      src/google/protobuf/message.cc
  4. 6
      src/google/protobuf/stubs/singleton.h

@ -64,6 +64,10 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
// Disable the whole test when we use tcmalloc for "draconian" heap checks, in
// which case tcmalloc will print warnings that fail the plugin tests.
#if !GOOGLE_PROTOBUF_HEAP_CHECK_DRACONIAN
namespace google { namespace google {
namespace protobuf { namespace protobuf {
namespace compiler { namespace compiler {
@ -1663,3 +1667,5 @@ TEST_F(EncodeDecodeTest, ProtoParseError) {
} // namespace compiler } // namespace compiler
} // namespace protobuf } // namespace protobuf
} // namespace google } // namespace google
#endif // !GOOGLE_PROTOBUF_HEAP_CHECK_DRACONIAN

@ -247,8 +247,14 @@ namespace {
UnknownFieldSet* empty_unknown_field_set_ = NULL; UnknownFieldSet* empty_unknown_field_set_ = NULL;
GOOGLE_PROTOBUF_DECLARE_ONCE(empty_unknown_field_set_once_); GOOGLE_PROTOBUF_DECLARE_ONCE(empty_unknown_field_set_once_);
void DeleteEmptyUnknownFieldSet() {
delete empty_unknown_field_set_;
empty_unknown_field_set_ = NULL;
}
void InitEmptyUnknownFieldSet() { void InitEmptyUnknownFieldSet() {
empty_unknown_field_set_ = new UnknownFieldSet; empty_unknown_field_set_ = new UnknownFieldSet;
internal::OnShutdown(&DeleteEmptyUnknownFieldSet);
} }
const UnknownFieldSet& GetEmptyUnknownFieldSet() { const UnknownFieldSet& GetEmptyUnknownFieldSet() {

@ -440,6 +440,30 @@ const internal::RepeatedFieldAccessor* Reflection::RepeatedFieldAccessor(
return NULL; return NULL;
} }
namespace internal {
namespace {
void ShutdownRepeatedFieldAccessor() {
Singleton<internal::RepeatedFieldPrimitiveAccessor<int32> >::ShutDown();
Singleton<internal::RepeatedFieldPrimitiveAccessor<uint32> >::ShutDown();
Singleton<internal::RepeatedFieldPrimitiveAccessor<int64> >::ShutDown();
Singleton<internal::RepeatedFieldPrimitiveAccessor<uint64> >::ShutDown();
Singleton<internal::RepeatedFieldPrimitiveAccessor<float> >::ShutDown();
Singleton<internal::RepeatedFieldPrimitiveAccessor<double> >::ShutDown();
Singleton<internal::RepeatedFieldPrimitiveAccessor<bool> >::ShutDown();
Singleton<internal::RepeatedPtrFieldStringAccessor>::ShutDown();
Singleton<internal::RepeatedPtrFieldMessageAccessor>::ShutDown();
Singleton<internal::MapFieldAccessor>::ShutDown();
};
struct ShutdownRepeatedFieldRegister {
ShutdownRepeatedFieldRegister() {
OnShutdown(&ShutdownRepeatedFieldAccessor);
}
} shutdown_;
} // namesapce
} // namespace internal
namespace internal { namespace internal {
// Macro defined in repeated_field.h. We can only define the Message-specific // Macro defined in repeated_field.h. We can only define the Message-specific
// GenericTypeHandler specializations here because we depend on Message, which // GenericTypeHandler specializations here because we depend on Message, which

@ -44,6 +44,10 @@ class Singleton {
GoogleOnceInit(&once_, &Singleton<T>::Init); GoogleOnceInit(&once_, &Singleton<T>::Init);
return instance_; return instance_;
} }
static void ShutDown() {
delete instance_;
instance_ = NULL;
}
private: private:
static void Init() { static void Init() {
instance_ = new T(); instance_ = new T();
@ -56,7 +60,7 @@ template<typename T>
ProtobufOnceType Singleton<T>::once_; ProtobufOnceType Singleton<T>::once_;
template<typename T> template<typename T>
T* Singleton<T>::instance_; T* Singleton<T>::instance_ = NULL;
} // namespace internal } // namespace internal
} // namespace protobuf } // namespace protobuf
} // namespace google } // namespace google

Loading…
Cancel
Save