forked from OSchip/llvm-project
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. llvm-svn: 119379
This commit is contained in:
parent
f2a1345a34
commit
3edb16765d
|
@ -830,7 +830,6 @@ error:
|
|||
if (OverrideMainBuffer) {
|
||||
PreprocessorOpts.eraseRemappedFile(
|
||||
PreprocessorOpts.remapped_file_buffer_end() - 1);
|
||||
PreprocessorOpts.DisablePCHValidation = true;
|
||||
PreprocessorOpts.ImplicitPCHInclude = PriorImplicitPCHInclude;
|
||||
delete OverrideMainBuffer;
|
||||
SavedMainFileBuffer = 0;
|
||||
|
@ -953,7 +952,6 @@ ASTUnit::ComputePreamble(CompilerInvocation &Invocation,
|
|||
}
|
||||
|
||||
static llvm::MemoryBuffer *CreatePaddedMainFileBuffer(llvm::MemoryBuffer *Old,
|
||||
bool DeleteOld,
|
||||
unsigned NewSize,
|
||||
llvm::StringRef NewName) {
|
||||
llvm::MemoryBuffer *Result
|
||||
|
@ -964,9 +962,6 @@ static llvm::MemoryBuffer *CreatePaddedMainFileBuffer(llvm::MemoryBuffer *Old,
|
|||
' ', NewSize - Old->getBufferSize() - 1);
|
||||
const_cast<char*>(Result->getBufferEnd())[-1] = '\n';
|
||||
|
||||
if (DeleteOld)
|
||||
delete Old;
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
|
@ -1002,6 +997,11 @@ llvm::MemoryBuffer *ASTUnit::getMainBufferWithPrecompiledPreamble(
|
|||
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::MemoryBuffer *ASTUnit::getMainBufferWithPrecompiledPreamble(
|
|||
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 @@ llvm::MemoryBuffer *ASTUnit::getMainBufferWithPrecompiledPreamble(
|
|||
// 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 @@ llvm::MemoryBuffer *ASTUnit::getMainBufferWithPrecompiledPreamble(
|
|||
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 @@ llvm::MemoryBuffer *ASTUnit::getMainBufferWithPrecompiledPreamble(
|
|||
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 @@ llvm::MemoryBuffer *ASTUnit::getMainBufferWithPrecompiledPreamble(
|
|||
// 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 @@ llvm::MemoryBuffer *ASTUnit::getMainBufferWithPrecompiledPreamble(
|
|||
PreprocessorOpts.eraseRemappedFile(
|
||||
PreprocessorOpts.remapped_file_buffer_end() - 1);
|
||||
return CreatePaddedMainFileBuffer(NewPreamble.first,
|
||||
CreatedPreambleBuffer,
|
||||
PreambleReservedSize,
|
||||
FrontendOpts.Inputs[0].second);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue