[cfe-commits] r119379 - /cfe/trunk/lib/Frontend/ASTUnit.cpp
Douglas Gregor
dgregor at apple.com
Tue Nov 16 12:45:51 PST 2010
Author: dgregor
Date: Tue Nov 16 14:45:51 2010
New Revision: 119379
URL: http://llvm.org/viewvc/llvm-project?rev=119379&view=rev
Log:
Use an OwningPtr for the preamble buffer in ASTUnit. This plugs a leak
where we failed to free this buffer along one of the paths, and
detangles the code a little.
Modified:
cfe/trunk/lib/Frontend/ASTUnit.cpp
Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=119379&r1=119378&r2=119379&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Tue Nov 16 14:45:51 2010
@@ -830,7 +830,6 @@
if (OverrideMainBuffer) {
PreprocessorOpts.eraseRemappedFile(
PreprocessorOpts.remapped_file_buffer_end() - 1);
- PreprocessorOpts.DisablePCHValidation = true;
PreprocessorOpts.ImplicitPCHInclude = PriorImplicitPCHInclude;
delete OverrideMainBuffer;
SavedMainFileBuffer = 0;
@@ -953,7 +952,6 @@
}
static llvm::MemoryBuffer *CreatePaddedMainFileBuffer(llvm::MemoryBuffer *Old,
- bool DeleteOld,
unsigned NewSize,
llvm::StringRef NewName) {
llvm::MemoryBuffer *Result
@@ -964,9 +962,6 @@
' ', NewSize - Old->getBufferSize() - 1);
const_cast<char*>(Result->getBufferEnd())[-1] = '\n';
- if (DeleteOld)
- delete Old;
-
return Result;
}
@@ -1002,6 +997,11 @@
std::pair<llvm::MemoryBuffer *, std::pair<unsigned, bool> > NewPreamble
= ComputePreamble(PreambleInvocation, MaxLines, CreatedPreambleBuffer);
+ // If ComputePreamble() Take ownership of the
+ llvm::OwningPtr<llvm::MemoryBuffer> OwnedPreambleBuffer;
+ if (CreatedPreambleBuffer)
+ OwnedPreambleBuffer.reset(NewPreamble.first);
+
if (!NewPreamble.second.first) {
// We couldn't find a preamble in the main source. Clear out the current
// preamble, if we have one. It's obviously no good any more.
@@ -1010,8 +1010,6 @@
llvm::sys::Path(PreambleFile).eraseFromDisk();
PreambleFile.clear();
}
- if (CreatedPreambleBuffer)
- delete NewPreamble.first;
// The next time we actually see a preamble, precompile it.
PreambleRebuildCounter = 1;
@@ -1108,7 +1106,6 @@
// Create a version of the main file buffer that is padded to
// buffer size we reserved when creating the preamble.
return CreatePaddedMainFileBuffer(NewPreamble.first,
- CreatedPreambleBuffer,
PreambleReservedSize,
FrontendOpts.Inputs[0].second);
}
@@ -1203,8 +1200,6 @@
if (!Clang.hasTarget()) {
llvm::sys::Path(FrontendOpts.OutputFile).eraseFromDisk();
Preamble.clear();
- if (CreatedPreambleBuffer)
- delete NewPreamble.first;
PreambleRebuildCounter = DefaultPreambleRebuildInterval;
PreprocessorOpts.eraseRemappedFile(
PreprocessorOpts.remapped_file_buffer_end() - 1);
@@ -1248,8 +1243,6 @@
Clang.takeInvocation();
llvm::sys::Path(FrontendOpts.OutputFile).eraseFromDisk();
Preamble.clear();
- if (CreatedPreambleBuffer)
- delete NewPreamble.first;
PreambleRebuildCounter = DefaultPreambleRebuildInterval;
PreprocessorOpts.eraseRemappedFile(
PreprocessorOpts.remapped_file_buffer_end() - 1);
@@ -1266,8 +1259,6 @@
// FIXME: Should we leave a note for ourselves to try again?
llvm::sys::Path(FrontendOpts.OutputFile).eraseFromDisk();
Preamble.clear();
- if (CreatedPreambleBuffer)
- delete NewPreamble.first;
TopLevelDeclsInPreamble.clear();
PreambleRebuildCounter = DefaultPreambleRebuildInterval;
PreprocessorOpts.eraseRemappedFile(
@@ -1302,7 +1293,6 @@
PreprocessorOpts.eraseRemappedFile(
PreprocessorOpts.remapped_file_buffer_end() - 1);
return CreatePaddedMainFileBuffer(NewPreamble.first,
- CreatedPreambleBuffer,
PreambleReservedSize,
FrontendOpts.Inputs[0].second);
}
More information about the cfe-commits
mailing list