blob: aeab9400511560e3998f7e331a5ffcb3d1f496ac [file] [log] [blame]
Index: gflags.cc
===================================================================
--- gflags.cc (revision 42)
+++ gflags.cc (working copy)
@@ -275,6 +275,10 @@
}
FlagValue::~FlagValue() {
+ /*
+ This class doesn't really own its value_buffer. I suspect that
+ this destructor is never called, otherwise it would surely crash.
+
switch (type_) {
case FV_BOOL: delete reinterpret_cast<bool*>(value_buffer_); break;
case FV_INT32: delete reinterpret_cast<int32*>(value_buffer_); break;
@@ -283,6 +287,7 @@
case FV_DOUBLE: delete reinterpret_cast<double*>(value_buffer_); break;
case FV_STRING: delete reinterpret_cast<string*>(value_buffer_); break;
}
+ */
}
bool FlagValue::ParseFrom(const char* value) {
@@ -611,6 +616,12 @@
class FlagRegistry {
public:
FlagRegistry() { }
+ ~FlagRegistry() {
+ for (FlagMap::iterator p = flags_.begin(), e = flags_.end(); p != e; ++p) {
+ CommandLineFlag* flag = p->second;
+ delete flag;
+ }
+ }
void Lock() { lock_.Lock(); }
void Unlock() { lock_.Unlock(); }
@@ -642,6 +653,12 @@
FlagSettingMode set_mode, string* msg);
static FlagRegistry* GlobalRegistry(); // returns a singleton registry
+ static void Cleanup() {
+ if (global_registry_ != NULL) {
+ delete global_registry_;
+ global_registry_ = NULL;
+ }
+ }
private:
friend class GOOGLE_NAMESPACE::FlagSaverImpl; // reads all the flags in order to copy them
@@ -679,6 +696,14 @@
return global_registry_;
}
+// It would be preferable to provide a cleanup method, rather than using
+// a static destructor, but this is easier to patch in.
+class CleanupGlobalRegistry {
+ public:
+ ~CleanupGlobalRegistry() { FlagRegistry::Cleanup(); }
+};
+CleanupGlobalRegistry cleanup_global_registry;
+
void FlagRegistry::RegisterFlag(CommandLineFlag* flag) {
Lock();
pair<FlagIterator, bool> ins =