[cfe-commits] r111504 - in /cfe/trunk: include/clang/Frontend/ASTUnit.h lib/Frontend/ASTUnit.cpp

Douglas Gregor dgregor at apple.com
Wed Aug 18 18:33:06 PDT 2010


Author: dgregor
Date: Wed Aug 18 20:33:06 2010
New Revision: 111504

URL: http://llvm.org/viewvc/llvm-project?rev=111504&view=rev
Log:
Plug a leak when precompiling the preamble in ASTUnit.

Modified:
    cfe/trunk/include/clang/Frontend/ASTUnit.h
    cfe/trunk/lib/Frontend/ASTUnit.cpp

Modified: cfe/trunk/include/clang/Frontend/ASTUnit.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/ASTUnit.h?rev=111504&r1=111503&r2=111504&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/ASTUnit.h (original)
+++ cfe/trunk/include/clang/Frontend/ASTUnit.h Wed Aug 18 20:33:06 2010
@@ -177,6 +177,11 @@
   /// preamble.
   llvm::MemoryBuffer *SavedMainFileBuffer;
 
+  /// \brief When non-NULL, this is the buffer used to store the
+  /// contents of the preamble when it has been padded to build the
+  /// precompiled preamble.
+  llvm::MemoryBuffer *PreambleBuffer;
+
   /// \brief The number of warnings that occurred while parsing the preamble.
   ///
   /// This value will be used to restore the state of the \c Diagnostic object

Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=111504&r1=111503&r2=111504&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Wed Aug 18 20:33:06 2010
@@ -52,7 +52,7 @@
 ASTUnit::ASTUnit(bool _MainFileIsAST)
   : CaptureDiagnostics(false), MainFileIsAST(_MainFileIsAST), 
     CompleteTranslationUnit(true), ConcurrencyCheckValue(CheckUnlocked), 
-    PreambleRebuildCounter(0), SavedMainFileBuffer(0),
+    PreambleRebuildCounter(0), SavedMainFileBuffer(0), PreambleBuffer(0),
     ShouldCacheCodeCompletionResults(false),
     NumTopLevelDeclsAtLastCompletionCache(0),
     CacheCodeCompletionCoolDown(0),
@@ -80,7 +80,8 @@
   }
   
   delete SavedMainFileBuffer;
-  
+  delete PreambleBuffer;
+
   ClearCachedCompletionResults();
   
   for (unsigned I = 0, N = Timers.size(); I != N; ++I)
@@ -646,8 +647,10 @@
   delete SavedMainFileBuffer;
   SavedMainFileBuffer = 0;
   
-  if (!Invocation.get())
+  if (!Invocation.get()) {
+    delete OverrideMainBuffer;
     return true;
+  }
   
   // Create the compiler instance to use for building the AST.
   CompilerInstance Clang;
@@ -664,9 +667,11 @@
   // Create the target instance.
   Clang.setTarget(TargetInfo::CreateTargetInfo(Clang.getDiagnostics(),
                                                Clang.getTargetOpts()));
-  if (!Clang.hasTarget())
+  if (!Clang.hasTarget()) {
+    delete OverrideMainBuffer;
     return true;
-  
+  }
+
   // Inform the target of the language options.
   //
   // FIXME: We shouldn't need to do this, the target should be immutable once
@@ -773,6 +778,7 @@
                                PreprocessorOpts.remapped_file_buffer_end() - 1);
     PreprocessorOpts.DisablePCHValidation = true;
     PreprocessorOpts.ImplicitPCHInclude = PriorImplicitPCHInclude;
+    delete OverrideMainBuffer;
   }
   
   Clang.takeSourceManager();
@@ -1092,7 +1098,8 @@
                                                   + NewPreamble.second.first);
   PreambleEndsAtStartOfLine = NewPreamble.second.second;
 
-  llvm::MemoryBuffer *PreambleBuffer
+  delete PreambleBuffer;
+  PreambleBuffer
     = llvm::MemoryBuffer::getNewUninitMemBuffer(PreambleReservedSize,
                                                 FrontendOpts.Inputs[0].second);
   memcpy(const_cast<char*>(PreambleBuffer->getBufferStart()), 
@@ -1135,6 +1142,8 @@
     if (PreambleTimer)
       PreambleTimer->stopTimer();
     PreambleRebuildCounter = DefaultPreambleRebuildInterval;
+    PreprocessorOpts.eraseRemappedFile(
+                               PreprocessorOpts.remapped_file_buffer_end() - 1);
     return 0;
   }
   
@@ -1174,7 +1183,8 @@
     if (PreambleTimer)
       PreambleTimer->stopTimer();
     PreambleRebuildCounter = DefaultPreambleRebuildInterval;
-
+    PreprocessorOpts.eraseRemappedFile(
+                               PreprocessorOpts.remapped_file_buffer_end() - 1);
     return 0;
   }
   
@@ -1194,6 +1204,8 @@
       PreambleTimer->stopTimer();
     TopLevelDeclsInPreamble.clear();
     PreambleRebuildCounter = DefaultPreambleRebuildInterval;
+    PreprocessorOpts.eraseRemappedFile(
+                               PreprocessorOpts.remapped_file_buffer_end() - 1);
     return 0;
   }
   
@@ -1224,6 +1236,8 @@
     PreambleTimer->stopTimer();
   
   PreambleRebuildCounter = 1;
+  PreprocessorOpts.eraseRemappedFile(
+                               PreprocessorOpts.remapped_file_buffer_end() - 1);
   return CreatePaddedMainFileBuffer(NewPreamble.first, 
                                     CreatedPreambleBuffer,
                                     PreambleReservedSize,





More information about the cfe-commits mailing list