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

Fangrui Song via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Apr 20 10:18:09 PDT 2021


MaskRay marked 2 inline comments as done.
MaskRay added inline comments.


================
Comment at: lldb/tools/driver/Driver.cpp:856
       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 '");
----------------
dblaikie wrote:
> MaskRay wrote:
> > dblaikie wrote:
> > > Can this code execute more than once? If it does I guess it'll really leak?
> > > 
> > > (if it's not meant to be called more than once, maybe something like:
> > > ```
> > > static std::string *x = nullptr;
> > > assert(!x);
> > > x = new std::string(argv0);
> > > ...
> > > ```
> > The function is only executed once. 
> If that's not enforced in any way (at least I can't see any) & the rest of the code looks like it would be OK being called more than once (I think?) - might be worth some checking?
The function is oneshot and from the called functions it should be clear the function cannot be executed more than once (otherwise, duplicate error messages).

I changed the function to `static` so that it is clear this is not used a library function.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100806/new/

https://reviews.llvm.org/D100806



More information about the lldb-commits mailing list