From 194406e244d05dab41de3936ec7f39ad41102586 Mon Sep 17 00:00:00 2001 From: Ilya Biryukov Date: Mon, 28 May 2018 12:11:37 +0000 Subject: [clangd] Fix leak sanitizers warnings in clangd The commit includes two changes: 1. Set DisableFree to false when building the ParsedAST. This is sane default, since clangd never wants to leak the AST. 2. Make sure CompilerInstance created in code completion is passed to the FrontendAction::BeginSourceFile call. We have to do this to make sure the memory buffers of remapped files are properly freed. Our tests do not produce any warnings under asan anymore. The changes are mostly trivial, just moving the code around. So sending without review. --- clang-tools-extra/clangd/ClangdUnit.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'clang-tools-extra/clangd/ClangdUnit.cpp') diff --git a/clang-tools-extra/clangd/ClangdUnit.cpp b/clang-tools-extra/clangd/ClangdUnit.cpp index 41f2df3669e..105bdb1fe8e 100644 --- a/clang-tools-extra/clangd/ClangdUnit.cpp +++ b/clang-tools-extra/clangd/ClangdUnit.cpp @@ -153,6 +153,10 @@ ParsedAST::Build(std::unique_ptr CI, std::unique_ptr Buffer, std::shared_ptr PCHs, IntrusiveRefCntPtr VFS) { + assert(CI); + // Command-line parsing sets DisableFree to true by default, but we don't want + // to leak memory in clangd. + CI->getFrontendOpts().DisableFree = false; const PrecompiledPreamble *PreamblePCH = Preamble ? &Preamble->Preamble : nullptr; -- cgit v1.2.3