Skip to content

Commit

Permalink
Set RetainRemappedFileBuffers to true
Browse files Browse the repository at this point in the history
Reported by David Welch in MaskRay#350.

This fixes double-free of llvm::MemoryBuffer when parsing fails.
  • Loading branch information
MaskRay committed Mar 29, 2019
1 parent 4c871d9 commit 3a364c8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/indexer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,7 @@ Index(SemaManager *manager, WorkingFiles *wfiles, VFS *vfs,
Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));
if (!Clang->hasTarget())
return {};
Clang->getPreprocessorOpts().RetainRemappedFileBuffers = true;
#if LLVM_VERSION_MAJOR >= 9 // rC357037
Clang->createFileManager(FS);
#else
Expand Down Expand Up @@ -1302,8 +1303,6 @@ Index(SemaManager *manager, WorkingFiles *wfiles, VFS *vfs,
<< (reason.empty() ? "" : ": " + reason);
return {};
}
for (auto &Buf : Bufs)
Buf.release();

std::vector<std::unique_ptr<IndexFile>> result;
for (auto &it : param.UID2File) {
Expand Down
3 changes: 1 addition & 2 deletions src/sema_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ std::unique_ptr<CompilerInstance> BuildCompilerInstance(
Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));
if (!Clang->hasTarget())
return nullptr;
Clang->getPreprocessorOpts().RetainRemappedFileBuffers = true;
// Construct SourceManager with UserFilesAreVolatile: true because otherwise
// RequiresNullTerminator: true may cause out-of-bounds read when a file is
// mmap'ed but is saved concurrently.
Expand Down Expand Up @@ -490,7 +491,6 @@ void *CompletionMain(void *manager_) {
Clang->setCodeCompletionConsumer(task->Consumer.release());
if (!Parse(*Clang))
continue;
Buf.release();

task->on_complete(&Clang->getCodeCompletionConsumer());
}
Expand Down Expand Up @@ -580,7 +580,6 @@ void *DiagnosticMain(void *manager_) {
continue;
if (!Parse(*Clang))
continue;
Buf.release();

auto Fill = [](const DiagBase &d, Diagnostic &ret) {
ret.range = lsRange{{d.range.start.line, d.range.start.column},
Expand Down

0 comments on commit 3a364c8

Please sign in to comment.