diff --git a/lldb/include/lldb/Host/linux/HostInfoLinux.h b/lldb/include/lldb/Host/linux/HostInfoLinux.h --- a/lldb/include/lldb/Host/linux/HostInfoLinux.h +++ b/lldb/include/lldb/Host/linux/HostInfoLinux.h @@ -28,6 +28,7 @@ public: static void Initialize(SharedLibraryDirectoryHelper *helper = nullptr); + static void Terminate(); static llvm::VersionTuple GetOSVersion(); static bool GetOSBuildString(std::string &s); diff --git a/lldb/source/Host/linux/HostInfoLinux.cpp b/lldb/source/Host/linux/HostInfoLinux.cpp --- a/lldb/source/Host/linux/HostInfoLinux.cpp +++ b/lldb/source/Host/linux/HostInfoLinux.cpp @@ -41,6 +41,13 @@ g_fields = new HostInfoLinuxFields(); } +void HostInfoLinux::Terminate() { + assert(g_fields && "Missing call to Initialize?"); + delete g_fields; + g_fields = nullptr; + HostInfoBase::Terminate(); +} + llvm::VersionTuple HostInfoLinux::GetOSVersion() { assert(g_fields && "Missing call to Initialize?"); llvm::call_once(g_fields->m_os_version_once_flag, []() { diff --git a/lldb/unittests/Host/HostInfoTest.cpp b/lldb/unittests/Host/HostInfoTest.cpp --- a/lldb/unittests/Host/HostInfoTest.cpp +++ b/lldb/unittests/Host/HostInfoTest.cpp @@ -60,3 +60,16 @@ EXPECT_TRUE(HostInfo::GetXcodeSDKPath(XcodeSDK("CeciNestPasUnOS.sdk")).empty()); } #endif + +TEST(HostInfoTestInitialization, InitTwice) { + llvm::VersionTuple Version; + { + SubsystemRAII subsystems; + Version = HostInfo::GetOSVersion(); + } + + { + SubsystemRAII subsystems; + EXPECT_EQ(Version, HostInfo::GetOSVersion()); + } +}