Author: Vitaly Buka Date: 2021-06-11T00:20:35-07:00 New Revision: f3f904563ec9ce8c7bfda83bbca19790cc4d9afc
URL: https://github.com/llvm/llvm-project/commit/f3f904563ec9ce8c7bfda83bbca19790cc4d9afc DIFF: https://github.com/llvm/llvm-project/commit/f3f904563ec9ce8c7bfda83bbca19790cc4d9afc.diff LOG: [lldb] Fix leak in test Test leaks if we run tools/lldb/unittests/Host/HostTests without --gtest_filter Reviewed By: teemperor Differential Revision: https://reviews.llvm.org/D104091 Added: Modified: lldb/include/lldb/Host/linux/HostInfoLinux.h lldb/source/Host/linux/HostInfoLinux.cpp lldb/unittests/Host/HostInfoTest.cpp Removed: ################################################################################ diff --git a/lldb/include/lldb/Host/linux/HostInfoLinux.h b/lldb/include/lldb/Host/linux/HostInfoLinux.h index e8080033cd8f8..4a7bb6cc11fbb 100644 --- a/lldb/include/lldb/Host/linux/HostInfoLinux.h +++ b/lldb/include/lldb/Host/linux/HostInfoLinux.h @@ -28,6 +28,7 @@ class HostInfoLinux : public HostInfoPosix { 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 index 36ac0ec6c3c37..6c37b97d7ccfb 100644 --- a/lldb/source/Host/linux/HostInfoLinux.cpp +++ b/lldb/source/Host/linux/HostInfoLinux.cpp @@ -41,6 +41,13 @@ void HostInfoLinux::Initialize(SharedLibraryDirectoryHelper *helper) { 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 index 96d47d75794a3..0accdd8dbcdbf 100644 --- a/lldb/unittests/Host/HostInfoTest.cpp +++ b/lldb/unittests/Host/HostInfoTest.cpp @@ -60,3 +60,16 @@ TEST_F(HostInfoTest, GetXcodeSDK) { 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()); + } +} _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits