Skip to content

Commit

Permalink
[lldb] Fix leak in test
Browse files Browse the repository at this point in the history
Test leaks if we run
tools/lldb/unittests/Host/HostTests without --gtest_filter

Reviewed By: teemperor

Differential Revision: https://reviews.llvm.org/D104091
  • Loading branch information
vitalybuka committed Jun 11, 2021
1 parent bc104fd commit f3f9045
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions lldb/include/lldb/Host/linux/HostInfoLinux.h
Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions lldb/source/Host/linux/HostInfoLinux.cpp
Expand Up @@ -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, []() {
Expand Down
13 changes: 13 additions & 0 deletions lldb/unittests/Host/HostInfoTest.cpp
Expand Up @@ -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());
}
}

0 comments on commit f3f9045

Please sign in to comment.