aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-02-27 01:32:48 +0000
committerDouglas Gregor <dgregor@apple.com>2010-02-27 01:32:48 +0000
commitc8dfe5ece04e683106eb96c58a2999f70b53ac21 (patch)
tree0042003e927d0563cd605faf6d398542cb50a7c1
parent5fe8c04009eff540ebaa0cceb2e75c3908322e11 (diff)
When given unsaved files in clang_createTranslationUnitFromSourceFile,
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
-rw-r--r--include/clang-c/Index.h6
-rw-r--r--lib/Frontend/ASTUnit.cpp1
-rw-r--r--lib/Frontend/InitPreprocessor.cpp3
-rw-r--r--tools/CIndex/CIndex.cpp2
4 files changed, 6 insertions, 6 deletions
diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h
index 6d1a02fb4f..c1238e5d88 100644
--- a/include/clang-c/Index.h
+++ b/include/clang-c/Index.h
@@ -87,14 +87,12 @@ struct CXUnsavedFile {
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;
};
diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp
index 8874622a24..ef14df1034 100644
--- a/lib/Frontend/ASTUnit.cpp
+++ b/lib/Frontend/ASTUnit.cpp
@@ -162,6 +162,7 @@ ASTUnit *ASTUnit::LoadFromPCHFile(const std::string &Filename,
if (!FromFile) {
Diags.Report(diag::err_fe_remap_missing_from_file)
<< RemappedFiles[I].first;
+ delete RemappedFiles[I].second;
continue;
}
diff --git a/lib/Frontend/InitPreprocessor.cpp b/lib/Frontend/InitPreprocessor.cpp
index b7ab3d8cd4..8bcd3a83c0 100644
--- a/lib/Frontend/InitPreprocessor.cpp
+++ b/lib/Frontend/InitPreprocessor.cpp
@@ -439,6 +439,7 @@ static void InitializeFileRemapping(Diagnostic &Diags,
if (!FromFile) {
Diags.Report(diag::err_fe_remap_missing_from_file)
<< Remap->first;
+ delete Remap->second;
continue;
}
@@ -477,7 +478,7 @@ static void InitializeFileRemapping(Diagnostic &Diags,
= llvm::MemoryBuffer::getFile(ToFile->getName(), &ErrorStr);
if (!Buffer) {
Diags.Report(diag::err_fe_error_opening)
- << Remap->second << ErrorStr;
+ << Remap->second << ErrorStr;
continue;
}
diff --git a/tools/CIndex/CIndex.cpp b/tools/CIndex/CIndex.cpp
index df89d73ba8..e13dddfcad 100644
--- a/tools/CIndex/CIndex.cpp
+++ b/tools/CIndex/CIndex.cpp
@@ -966,7 +966,7 @@ clang_createTranslationUnitFromSourceFile(CXIndex CIdx,
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,