]> granicus.if.org Git - clang/commitdiff
Fix a nasty little use-after-free bug.
authorEli Friedman <eli.friedman@gmail.com>
Wed, 22 Jul 2009 20:29:16 +0000 (20:29 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Wed, 22 Jul 2009 20:29:16 +0000 (20:29 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@76779 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ASTContext.cpp

index d489d4e73fa8e387f904627b63aa7b4c161d51ea..4490e9a3a9c06809c9d34f3834acef97963e44c3 100644 (file)
@@ -908,12 +908,14 @@ const ASTRecordLayout &ASTContext::getASTRecordLayout(const RecordDecl *D) {
   assert(D && "Cannot get layout of forward declarations!");
 
   // Look up this layout, if already laid out, return what we have.
-  const ASTRecordLayout *&Entry = ASTRecordLayouts[D];
+  // Note that we can't save a reference to the entry because this function
+  // is recursive.
+  const ASTRecordLayout *Entry = ASTRecordLayouts[D];
   if (Entry) return *Entry;
 
   const ASTRecordLayout *NewEntry = 
     ASTRecordLayoutBuilder::ComputeLayout(*this, D);
-  Entry = NewEntry;
+  ASTRecordLayouts[D] = NewEntry;
   
   return *NewEntry;
 }