[clangd] Fix memory leak in ClangdTests.
authorHaojian Wu <hokein@google.com>
Fri, 14 Dec 2018 13:19:38 +0000 (13:19 +0000)
committerHaojian Wu <hokein@google.com>
Fri, 14 Dec 2018 13:19:38 +0000 (13:19 +0000)
Summary:
createInvocationFromCommandLine sets DisableFree to true by default,
which leads memory leak in clangd. The fix is to  use the `BuildCompilationInvocation`
to create CI with the correct options (DisableFree is false).

Fix https://bugs.llvm.org/show_bug.cgi?id=39991.

Reviewers: kadircet

Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D55702

llvm-svn: 349145

clang-tools-extra/unittests/clangd/TestTU.cpp

index e8fb63c..4e14262 100644 (file)
@@ -38,8 +38,10 @@ ParsedAST TestTU::build() const {
   Inputs.Contents = Code;
   Inputs.FS = buildTestFS({{FullFilename, Code}, {FullHeaderName, HeaderCode}});
   auto PCHs = std::make_shared<PCHContainerOperations>();
+  auto CI = buildCompilerInvocation(Inputs);
+  assert(CI && "Failed to build compilation invocation.");
   auto Preamble =
-      buildPreamble(FullFilename, *createInvocationFromCommandLine(Cmd),
+      buildPreamble(FullFilename, *CI,
                     /*OldPreamble=*/nullptr,
                     /*OldCompileCommand=*/Inputs.CompileCommand, Inputs, PCHs,
                     /*StoreInMemory=*/true, /*PreambleCallback=*/nullptr);