copy the source buffers provided rather than referencing them
directly, so that the caller can free those buffers immediately after
calling clang_createTranslationUnitFromSourceFile(). Otherwise, we
risk hitting those buffers later (when building source ranges, forming
diagnostics, etc.).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@97296
91177308-0d34-0410-b5e6-
96231b3b80d8
const char *Filename;
/**
- * \brief A null-terminated buffer containing the unsaved contents
- * of this file.
+ * \brief A buffer containing the unsaved contents of this file.
*/
const char *Contents;
/**
- * \brief The length of the unsaved contents of this buffer, not
- * counting the NULL at the end of the buffer.
+ * \brief The length of the unsaved contents of this buffer.
*/
unsigned long Length;
};
if (!FromFile) {
Diags.Report(diag::err_fe_remap_missing_from_file)
<< RemappedFiles[I].first;
+ delete RemappedFiles[I].second;
continue;
}
if (!FromFile) {
Diags.Report(diag::err_fe_remap_missing_from_file)
<< Remap->first;
+ delete Remap->second;
continue;
}
= llvm::MemoryBuffer::getFile(ToFile->getName(), &ErrorStr);
if (!Buffer) {
Diags.Report(diag::err_fe_error_opening)
- << Remap->second << ErrorStr;
+ << Remap->second << ErrorStr;
continue;
}
llvm::SmallVector<ASTUnit::RemappedFile, 4> RemappedFiles;
for (unsigned I = 0; I != num_unsaved_files; ++I) {
const llvm::MemoryBuffer *Buffer
- = llvm::MemoryBuffer::getMemBuffer(unsaved_files[I].Contents,
+ = llvm::MemoryBuffer::getMemBufferCopy(unsaved_files[I].Contents,
unsaved_files[I].Contents + unsaved_files[I].Length,
unsaved_files[I].Filename);
RemappedFiles.push_back(std::make_pair(unsaved_files[I].Filename,