Fix use-after-free warning in repl.cc#13497
Conversation
|
NAK. The PR does not fix any use-after-free or double-free. Instead it prevents the destructor of First, the life-time of the allocated objects ends when the function returns. During its life-time the The class Maybe the warning is caused by this line of code because the constructor of |
|
Ok. I'll find a way to make turn the warning off for this line than. |
The clang-analyzer incorrectly flags a use-after-free for GC-managed objects when used with std::unique_ptr. Since NixRepl inherits from gc, its memory is properly managed by Boehm GC and this is a false positive. Added NOLINTNEXTLINE directive to suppress the warning.
96d7294 to
0675094
Compare
NixRepl inherits from gc which uses Boehm GC for memory management. Using std::unique_ptr with GC-managed objects causes use-after-free because unique_ptr calls delete while the GC expects to manage the memory itself.
Replace std::make_unique with raw pointer allocation to let the GC handle memory management properly.
Fixes clang-tidy warning: Use of memory after it is freed [clang-analyzer-cplusplus.NewDelete]
Isolated from: #13494 because of #13494 (comment)
Motivation
Context
Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.