[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:04:13 PDT 2021


vitalybuka updated this revision to Diff 351347.
vitalybuka marked 2 inline comments as done.
vitalybuka edited the summary of this revision.
vitalybuka added a comment.

::Terminate


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.351347.patch
Type: text/x-patch
Size: 1661 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20210611/6d8ecda4/attachment.bin>


More information about the lldb-commits mailing list