[Lldb-commits] [PATCH] D100806: [lldb] Fix one leak in reproducer

Fangrui Song via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Apr 19 17:59:39 PDT 2021


MaskRay created this revision.
MaskRay added reviewers: JDevlieghere, rupprecht, shafik, teemperor.
MaskRay requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Use a variable of static storage duration to reference an intentionally
leaked variable. A static data area is in the GC-set of various leak
checkers.

This fixes 3 `check-lldb-shell` tests in a `-DLLVM_USE_SANITIZER={Leaks,Address}` build,
e.g. `test/Shell/Reproducer/TestHomeDir.test`


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100806

Files:
  lldb/tools/driver/Driver.cpp


Index: lldb/tools/driver/Driver.cpp
===================================================================
--- lldb/tools/driver/Driver.cpp
+++ lldb/tools/driver/Driver.cpp
@@ -784,8 +784,8 @@
   llvm::outs() << examples << '\n';
 }
 
-llvm::Optional<int> InitializeReproducer(llvm::StringRef argv0,
-                                         opt::InputArgList &input_args) {
+static llvm::Optional<int> InitializeReproducer(llvm::StringRef argv0,
+                                                opt::InputArgList &input_args) {
   if (auto *finalize_path = input_args.getLastArg(OPT_reproducer_finalize)) {
     if (const char *error = SBReproducer::Finalize(finalize_path->getValue())) {
       WithColor::error() << "reproducer finalization failed: " << error << '\n';
@@ -854,7 +854,7 @@
     if (!input_args.hasArg(OPT_no_generate_on_signal)) {
       if (const char *reproducer_path = SBReproducer::GetPath()) {
         // Leaking the string on purpose.
-        std::string *finalize_cmd = new std::string(argv0);
+        static std::string *finalize_cmd = new std::string(argv0);
         finalize_cmd->append(" --reproducer-finalize '");
         finalize_cmd->append(reproducer_path);
         finalize_cmd->append("'");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100806.338679.patch
Type: text/x-patch
Size: 1230 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20210420/1013bc57/attachment.bin>


More information about the lldb-commits mailing list