r214281 - Fix a use after free bug.

Rafael Espindola rafael.espindola at gmail.com
Tue Jul 29 19:37:27 PDT 2014


Author: rafael
Date: Tue Jul 29 21:37:26 2014
New Revision: 214281

URL: http://llvm.org/viewvc/llvm-project?rev=214281&view=rev
Log:
Fix a use after free bug.

Modified:
    cfe/trunk/lib/AST/ASTContext.cpp

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=214281&r1=214280&r2=214281&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Tue Jul 29 21:37:26 2014
@@ -1432,11 +1432,14 @@ bool ASTContext::isAlignmentRequired(Qua
 }
 
 TypeInfo ASTContext::getTypeInfo(const Type *T) const {
-  TypeInfo &TI = MemoizedTypeInfo[T];
-  if (!TI.Align)
-    TI = getTypeInfoImpl(T);
+  TypeInfo TI = MemoizedTypeInfo[T];
+  if (TI.Align)
+    return TI;
 
-  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





More information about the cfe-commits mailing list