aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/stubs/common.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/google/protobuf/stubs/common.cc')
-rw-r--r--src/google/protobuf/stubs/common.cc42
1 files changed, 28 insertions, 14 deletions
diff --git a/src/google/protobuf/stubs/common.cc b/src/google/protobuf/stubs/common.cc
index 14655916..78aa4d64 100644
--- a/src/google/protobuf/stubs/common.cc
+++ b/src/google/protobuf/stubs/common.cc
@@ -416,13 +416,26 @@ uint32 ghtonl(uint32 x) {
namespace internal {
typedef void OnShutdownFunc();
-vector<void (*)()>* shutdown_functions = NULL;
-Mutex* shutdown_functions_mutex = NULL;
+struct ShutdownData {
+ ~ShutdownData() {
+ for (int i = 0; i < functions.size(); i++) {
+ functions[i]();
+ }
+ for (int i = 0; i < strings.size(); i++) {
+ strings[i]->~string();
+ }
+ }
+
+ vector<void (*)()> functions;
+ vector<const std::string*> strings;
+ Mutex mutex;
+};
+
+ShutdownData* shutdown_data = NULL;
GOOGLE_PROTOBUF_DECLARE_ONCE(shutdown_functions_init);
void InitShutdownFunctions() {
- shutdown_functions = new vector<void (*)()>;
- shutdown_functions_mutex = new Mutex;
+ shutdown_data = new ShutdownData;
}
inline void InitShutdownFunctionsOnce() {
@@ -431,8 +444,14 @@ inline void InitShutdownFunctionsOnce() {
void OnShutdown(void (*func)()) {
InitShutdownFunctionsOnce();
- MutexLock lock(shutdown_functions_mutex);
- shutdown_functions->push_back(func);
+ MutexLock lock(&shutdown_data->mutex);
+ shutdown_data->functions.push_back(func);
+}
+
+void OnShutdownDestroyString(const std::string* ptr) {
+ InitShutdownFunctionsOnce();
+ MutexLock lock(&shutdown_data->mutex);
+ shutdown_data->strings.push_back(ptr);
}
} // namespace internal
@@ -445,15 +464,10 @@ void ShutdownProtobufLibrary() {
// called.
// Make it safe to call this multiple times.
- if (internal::shutdown_functions == NULL) return;
+ if (internal::shutdown_data == NULL) return;
- for (int i = 0; i < internal::shutdown_functions->size(); i++) {
- internal::shutdown_functions->at(i)();
- }
- delete internal::shutdown_functions;
- internal::shutdown_functions = NULL;
- delete internal::shutdown_functions_mutex;
- internal::shutdown_functions_mutex = NULL;
+ delete internal::shutdown_data;
+ internal::shutdown_data = NULL;
}
#if PROTOBUF_USE_EXCEPTIONS