[Lldb-commits] [PATCH] D104091: [NFC][lldb] Fix leak in test
    Raphael Isemann via Phabricator via lldb-commits 
    lldb-commits at lists.llvm.org
       
    Thu Jun 10 23:45:27 PDT 2021
    
    
  
teemperor requested changes to this revision.
teemperor added a comment.
This revision now requires changes to proceed.
I think we should instead implement the `Terminate` function that the plugin system provides to tear down our state. I made a patch in D104093 <https://reviews.llvm.org/D104093> that
moves the `once_flags` to the internal state struct, so with a proper `Terminate` implementation + my patch this should all work properly.
  HostInfoLinux::Terminate() {
    assert(g_fields && "Missing call to Initialize?");
    delete g_fields;
    g_fields = nullptr;
    HostInfoBase::Terminate();
  }
================
Comment at: lldb/source/Host/linux/HostInfoLinux.cpp:38
   HostInfoPosix::Initialize(helper);
-
-  g_fields = new HostInfoLinuxFields();
+  if (!g_fields)
+    g_fields = new HostInfoLinuxFields();
----------------
Please instead add a `HostInfoLinux::Terminate()` function that deletes and zeroes `g_fields` (see `HostInfoBase::Terminate`). Initialize -> Terminate should set up and tear down the data structures if possible (not saying that LLDB is doing this consistently at the moment, but that's the idea at least).
Repository:
  rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104091/new/
https://reviews.llvm.org/D104091
    
    
More information about the lldb-commits
mailing list