]> granicus.if.org Git - clang/commitdiff
Fix a use after free bug.
authorRafael Espindola <rafael.espindola@gmail.com>
Wed, 30 Jul 2014 02:37:26 +0000 (02:37 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Wed, 30 Jul 2014 02:37:26 +0000 (02:37 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@214281 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ASTContext.cpp

index c7685e4a6dd09c12cab9df24151510d5012dd94c..ea18d562b436d5cf539e3586984e397f6f0efc3b 100644 (file)
@@ -1432,11 +1432,14 @@ bool ASTContext::isAlignmentRequired(QualType T) const {
 }
 
 TypeInfo ASTContext::getTypeInfo(const Type *T) const {
-  TypeInfo &TI = MemoizedTypeInfo[T];
-  if (!TI.Align)
-    TI = getTypeInfoImpl(T);
-
-  return TI;
+  TypeInfo TI = MemoizedTypeInfo[T];
+  if (TI.Align)
+    return TI;
+
+  // This call can invalidate TI, so we need a second lookup.
+  TypeInfo Temp = getTypeInfoImpl(T);
+  MemoizedTypeInfo[T] = Temp;
+  return Temp;
 }
 
 /// getTypeInfoImpl - Return the size of the specified type, in bits.  This