mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-24 08:35:08 +00:00
Set RetainRemappedFileBuffers to true
Reported by David Welch in #350. This fixes double-free of llvm::MemoryBuffer when parsing fails.
This commit is contained in:
parent
aded3faf97
commit
b69f62c2bc
@ -1256,6 +1256,7 @@ Index(SemaManager *manager, WorkingFiles *wfiles, VFS *vfs,
|
|||||||
Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));
|
Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));
|
||||||
if (!Clang->hasTarget())
|
if (!Clang->hasTarget())
|
||||||
return {};
|
return {};
|
||||||
|
Clang->getPreprocessorOpts().RetainRemappedFileBuffers = true;
|
||||||
#if LLVM_VERSION_MAJOR >= 9 // rC357037
|
#if LLVM_VERSION_MAJOR >= 9 // rC357037
|
||||||
Clang->createFileManager(FS);
|
Clang->createFileManager(FS);
|
||||||
#else
|
#else
|
||||||
@ -1302,8 +1303,6 @@ Index(SemaManager *manager, WorkingFiles *wfiles, VFS *vfs,
|
|||||||
LOG_S(ERROR) << "failed to index " << main;
|
LOG_S(ERROR) << "failed to index " << main;
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
for (auto &Buf : Bufs)
|
|
||||||
Buf.release();
|
|
||||||
|
|
||||||
std::vector<std::unique_ptr<IndexFile>> result;
|
std::vector<std::unique_ptr<IndexFile>> result;
|
||||||
for (auto &it : param.UID2File) {
|
for (auto &it : param.UID2File) {
|
||||||
|
@ -313,6 +313,7 @@ std::unique_ptr<CompilerInstance> BuildCompilerInstance(
|
|||||||
Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));
|
Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));
|
||||||
if (!Clang->hasTarget())
|
if (!Clang->hasTarget())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
Clang->getPreprocessorOpts().RetainRemappedFileBuffers = true;
|
||||||
// Construct SourceManager with UserFilesAreVolatile: true because otherwise
|
// Construct SourceManager with UserFilesAreVolatile: true because otherwise
|
||||||
// RequiresNullTerminator: true may cause out-of-bounds read when a file is
|
// RequiresNullTerminator: true may cause out-of-bounds read when a file is
|
||||||
// mmap'ed but is saved concurrently.
|
// mmap'ed but is saved concurrently.
|
||||||
@ -493,7 +494,6 @@ void *CompletionMain(void *manager_) {
|
|||||||
Clang->setCodeCompletionConsumer(task->Consumer.release());
|
Clang->setCodeCompletionConsumer(task->Consumer.release());
|
||||||
if (!Parse(*Clang))
|
if (!Parse(*Clang))
|
||||||
continue;
|
continue;
|
||||||
Buf.release();
|
|
||||||
|
|
||||||
task->on_complete(&Clang->getCodeCompletionConsumer());
|
task->on_complete(&Clang->getCodeCompletionConsumer());
|
||||||
}
|
}
|
||||||
@ -583,7 +583,6 @@ void *DiagnosticMain(void *manager_) {
|
|||||||
continue;
|
continue;
|
||||||
if (!Parse(*Clang))
|
if (!Parse(*Clang))
|
||||||
continue;
|
continue;
|
||||||
Buf.release();
|
|
||||||
|
|
||||||
auto Fill = [](const DiagBase &d, Diagnostic &ret) {
|
auto Fill = [](const DiagBase &d, Diagnostic &ret) {
|
||||||
ret.range = lsRange{{d.range.start.line, d.range.start.column},
|
ret.range = lsRange{{d.range.start.line, d.range.start.column},
|
||||||
|
Loading…
Reference in New Issue
Block a user