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 @@ -35,8 +35,8 @@ void HostInfoLinux::Initialize(SharedLibraryDirectoryHelper *helper) { HostInfoPosix::Initialize(helper); - - g_fields = new HostInfoLinuxFields(); + if (!g_fields) + g_fields = new HostInfoLinuxFields(); } llvm::VersionTuple HostInfoLinux::GetOSVersion() { 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(HostInfoTest2, InitTwice) { + llvm::VersionTuple Version; + { + SubsystemRAII subsystems; + Version = HostInfo::GetOSVersion(); + } + + { + SubsystemRAII subsystems; + EXPECT_EQ(Version, HostInfo::GetOSVersion()); + } +}