[Lldb-commits] [PATCH] D104091: [lldb] Fix leak in test

Vitaly Buka via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri Jun 11 00:20:48 PDT 2021


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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104091.351351.patch
Type: text/x-patch
Size: 1661 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20210611/588e842d/attachment-0001.bin>


More information about the lldb-commits mailing list