diff --git a/include/rocksdb/utilities/object_registry.h b/include/rocksdb/utilities/object_registry.h index 9730ed1b13..b6751cae87 100644 --- a/include/rocksdb/utilities/object_registry.h +++ b/include/rocksdb/utilities/object_registry.h @@ -278,6 +278,9 @@ class ObjectRegistry { static std::shared_ptr Default(); explicit ObjectRegistry(const std::shared_ptr& parent) : parent_(parent) {} + explicit ObjectRegistry(const std::shared_ptr& library) { + libraries_.push_back(library); + } std::shared_ptr AddLibrary(const std::string& id) { auto library = std::make_shared(id); @@ -498,9 +501,6 @@ class ObjectRegistry { void Dump(Logger* logger) const; private: - explicit ObjectRegistry(const std::shared_ptr& library) { - libraries_.push_back(library); - } static std::string ToManagedObjectKey(const std::string& type, const std::string& id) { return type + "://" + id; diff --git a/utilities/object_registry.cc b/utilities/object_registry.cc index 7b0a6bb5a8..61820620f8 100644 --- a/utilities/object_registry.cc +++ b/utilities/object_registry.cc @@ -8,6 +8,7 @@ #include #include "logging/logging.h" +#include "port/lang.h" #include "rocksdb/customizable.h" #include "rocksdb/env.h" #include "util/string_util.h" @@ -135,14 +136,18 @@ void ObjectLibrary::Dump(Logger *logger) const { // Returns the Default singleton instance of the ObjectLibrary // This instance will contain most of the "standard" registered objects std::shared_ptr &ObjectLibrary::Default() { - static std::shared_ptr instance = - std::make_shared("default"); + // Use avoid destruction here so the default ObjectLibrary will not be + // statically destroyed and long-lived. + STATIC_AVOID_DESTRUCTION(std::shared_ptr, instance) + (std::make_shared("default")); return instance; } std::shared_ptr ObjectRegistry::Default() { - static std::shared_ptr instance( - new ObjectRegistry(ObjectLibrary::Default())); + // Use avoid destruction here so the default ObjectRegistry will not be + // statically destroyed and long-lived. + STATIC_AVOID_DESTRUCTION(std::shared_ptr, instance) + (std::make_shared(ObjectLibrary::Default())); return instance; }