diff --git a/src/quick-lint-js/container/vector-profiler.cpp b/src/quick-lint-js/container/vector-profiler.cpp index 71437b8dba..490637cb9d 100644 --- a/src/quick-lint-js/container/vector-profiler.cpp +++ b/src/quick-lint-js/container/vector-profiler.cpp @@ -24,8 +24,12 @@ QLJS_WARNING_IGNORE_MSVC(4996) // Function or variable may be unsafe. namespace quick_lint_js { #if QLJS_FEATURE_VECTOR_PROFILING Vector_Instrumentation &Vector_Instrumentation::instance() { - static Vector_Instrumentation instrumentation; - return instrumentation; + // NOTE(strager): We intentionally leak the Vector_Instrumentation. We want to + // avoid deinitialization order issues, so defer deinitialization forever. + // Also, cleaning up the memory is wasteful and is unnecessary for modern leak + // checkers anyway. + static Vector_Instrumentation *instrumentation = new Vector_Instrumentation(); + return *instrumentation; } #endif diff --git a/src/quick-lint-js/debug/debug-server.cpp b/src/quick-lint-js/debug/debug-server.cpp index 45b0523186..b8734b770e 100644 --- a/src/quick-lint-js/debug/debug-server.cpp +++ b/src/quick-lint-js/debug/debug-server.cpp @@ -110,7 +110,7 @@ std::shared_ptr Debug_Server::create() { return instance; } -Raw_Vector> Debug_Server::instances() { +Vector> Debug_Server::instances() { return Instance_Tracker::instances(); } diff --git a/src/quick-lint-js/debug/debug-server.h b/src/quick-lint-js/debug/debug-server.h index a35cb3d233..b8186c8502 100644 --- a/src/quick-lint-js/debug/debug-server.h +++ b/src/quick-lint-js/debug/debug-server.h @@ -35,7 +35,7 @@ class Debug_Server { public: static std::shared_ptr create(); - static Raw_Vector> instances(); + static Vector> instances(); explicit Debug_Server(Create_Tag); diff --git a/src/quick-lint-js/logging/logger.cpp b/src/quick-lint-js/logging/logger.cpp index 0ee1c56b65..584af20506 100644 --- a/src/quick-lint-js/logging/logger.cpp +++ b/src/quick-lint-js/logging/logger.cpp @@ -32,10 +32,7 @@ QLJS_WARNING_IGNORE_GCC("-Wsuggest-attribute=format") namespace quick_lint_js { namespace { struct Global_Loggers { - // NOTE(strager): We use Raw_Vector here instead of Vector. Otherwise, in - // vector instrumented builds, loggers might be initialized before the vector - // profiler is initialized, causing use-before-init issues. - Raw_Vector loggers{new_delete_resource()}; + Vector loggers{"Global_Loggers::loggers", new_delete_resource()}; bool initialized = false; void initialize_if_needed() { diff --git a/src/quick-lint-js/util/instance-tracker.h b/src/quick-lint-js/util/instance-tracker.h index 5a526db6eb..74c1bf9d7a 100644 --- a/src/quick-lint-js/util/instance-tracker.h +++ b/src/quick-lint-js/util/instance-tracker.h @@ -18,16 +18,17 @@ template class Instance_Tracker { public: static void track(std::shared_ptr instance) { - Lock_Ptr>> weak_instances = + Lock_Ptr>> weak_instances = weak_instances_.lock(); sanitize_instances(weak_instances); weak_instances->push_back(std::move(instance)); } - static Raw_Vector> instances() { - Raw_Vector> instances(new_delete_resource()); + static Vector> instances() { + Vector> instances("instances", + new_delete_resource()); { - Lock_Ptr>> weak_instances = + Lock_Ptr>> weak_instances = weak_instances_.lock(); sanitize_instances(weak_instances); instances.reserve(weak_instances->size()); @@ -45,7 +46,7 @@ class Instance_Tracker { private: static void sanitize_instances( - Lock_Ptr>>& weak_instances) { + Lock_Ptr>>& weak_instances) { erase_if(*weak_instances, [](const std::weak_ptr& weak_instance) { return weak_instance.expired(); }); @@ -55,11 +56,8 @@ class Instance_Tracker { sanitize_instances(weak_instances_.lock()); } - // NOTE(strager): We use Raw_Vector here instead of Vector. Otherwise, in - // vector instrumented builds, weak_instances_ might be initialized before the - // vector profiler is initialized, causing use-before-init issues. - static inline Synchronized>> - weak_instances_{new_delete_resource()}; + static inline Synchronized>> weak_instances_{ + "weak_instances_", new_delete_resource()}; }; }