[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
This commit is contained in:
Vitaly Buka 2021-06-10 18:43:35 -07:00
parent bc104fdcec
commit f3f904563e
3 changed files with 21 additions and 0 deletions

View File

@ -28,6 +28,7 @@ private:
public:
static void Initialize(SharedLibraryDirectoryHelper *helper = nullptr);
static void Terminate();
static llvm::VersionTuple GetOSVersion();
static bool GetOSBuildString(std::string &s);

View File

@ -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, []() {

View File

@ -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());
}
}