[cfe-commits] r61943 - /cfe/trunk/lib/AST/DeclObjC.cpp

Ted Kremenek kremenek at apple.com
Thu Jan 8 12:49:27 PST 2009


Author: kremenek
Date: Thu Jan  8 14:49:27 2009
New Revision: 61943

URL: http://llvm.org/viewvc/llvm-project?rev=61943&view=rev
Log:
Fix ObjCInterfaceDecl::Destroy and ObjCProtocolDecl::Destroy to iterate and destroy all contained ObjCMethodDecls in one sweep.  This fixes a use-after-free error found by valgrind.

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

Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=61943&r1=61942&r2=61943&view=diff

==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Thu Jan  8 14:49:27 2009
@@ -73,11 +73,8 @@
   for (ivar_iterator I=ivar_begin(), E=ivar_end(); I!=E; ++I)
     if (*I) (*I)->Destroy(C);
   
-  for (instmeth_iterator I=instmeth_begin(), E=instmeth_end(); I!=E; ++I)
-    if (*I) (*I)->Destroy(C);
-  
-  for (classmeth_iterator I=classmeth_begin(), E=classmeth_end(); I!=E; ++I)
-    if (*I) (*I)->Destroy(C);
+  for (method_iterator I=meth_begin(), E=meth_end(); I!=E; ++I)
+    if (*I) const_cast<ObjCMethodDecl*>((*I))->Destroy(C);
 
   // FIXME: Because there is no clear ownership
   //  role between ObjCInterfaceDecls and the ObjCPropertyDecls that they
@@ -122,11 +119,8 @@
   
   // Referenced Protocols are not owned, so don't Destroy them.
   
-  for (instmeth_iterator I=instmeth_begin(), E=instmeth_end(); I!=E; ++I)
-    if (*I) (*I)->Destroy(C);
-  
-  for (classmeth_iterator I=classmeth_begin(), E=classmeth_end(); I!=E; ++I)
-    if (*I) (*I)->Destroy(C);
+  for (method_iterator I=meth_begin(), E=meth_end(); I!=E; ++I)
+    if (*I) const_cast<ObjCMethodDecl*>((*I))->Destroy(C);
   
   // FIXME: Because there is no clear ownership
   //  role between ObjCProtocolDecls and the ObjCPropertyDecls that they





More information about the cfe-commits mailing list