This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rGf3f904563ec9: [lldb] Fix leak in test (authored by vitalybuka).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D104091/new/ https://reviews.llvm.org/D104091 Files: lldb/include/lldb/Host/linux/HostInfoLinux.h lldb/source/Host/linux/HostInfoLinux.cpp lldb/unittests/Host/HostInfoTest.cpp Index: lldb/unittests/Host/HostInfoTest.cpp =================================================================== --- lldb/unittests/Host/HostInfoTest.cpp +++ 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<FileSystem, HostInfo> subsystems; + Version = HostInfo::GetOSVersion(); + } + + { + SubsystemRAII<FileSystem, HostInfo> subsystems; + EXPECT_EQ(Version, HostInfo::GetOSVersion()); + } +} Index: lldb/source/Host/linux/HostInfoLinux.cpp =================================================================== --- lldb/source/Host/linux/HostInfoLinux.cpp +++ 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, []() { Index: lldb/include/lldb/Host/linux/HostInfoLinux.h =================================================================== --- lldb/include/lldb/Host/linux/HostInfoLinux.h +++ 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);
Index: lldb/unittests/Host/HostInfoTest.cpp =================================================================== --- lldb/unittests/Host/HostInfoTest.cpp +++ 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<FileSystem, HostInfo> subsystems; + Version = HostInfo::GetOSVersion(); + } + + { + SubsystemRAII<FileSystem, HostInfo> subsystems; + EXPECT_EQ(Version, HostInfo::GetOSVersion()); + } +} Index: lldb/source/Host/linux/HostInfoLinux.cpp =================================================================== --- lldb/source/Host/linux/HostInfoLinux.cpp +++ 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, []() { Index: lldb/include/lldb/Host/linux/HostInfoLinux.h =================================================================== --- lldb/include/lldb/Host/linux/HostInfoLinux.h +++ 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);
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits