Explorar o código

Fix the memory leak of GetEmptyString().

Feng Xiao %!s(int64=11) %!d(string=hai) anos
pai
achega
06e6690bf2
Modificáronse 1 ficheiros con 5 adicións e 1 borrados
  1. 5 1
      src/google/protobuf/generated_message_util.cc

+ 5 - 1
src/google/protobuf/generated_message_util.cc

@@ -36,7 +36,6 @@
 
 #include <limits>
 
-
 namespace google {
 namespace protobuf {
 namespace internal {
@@ -51,8 +50,13 @@ double NaN() {
 const ::std::string* empty_string_;
 GOOGLE_PROTOBUF_DECLARE_ONCE(empty_string_once_init_);
 
+void DeleteEmptyString() {
+  delete empty_string_;
+}
+
 void InitEmptyString() {
   empty_string_ = new string;
+  OnShutdown(&DeleteEmptyString);
 }