diff options
author | Ted Kremenek <kremenek@apple.com> | 2009-01-08 20:49:27 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2009-01-08 20:49:27 +0000 |
commit | 6321c0aaa3523f3d569d5fbe5820b3fa250e2585 (patch) | |
tree | fc8bb009175d41d3f3bc46ef7ce4798d5c55eafa | |
parent | 25553512a50e8c79fb1daae4b0398086be338554 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61943 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/AST/DeclObjC.cpp | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp index 2263af7d90..b7c0cf79b9 100644 --- a/lib/AST/DeclObjC.cpp +++ b/lib/AST/DeclObjC.cpp @@ -73,11 +73,8 @@ void ObjCInterfaceDecl::Destroy(ASTContext& C) { 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 @@ void ObjCProtocolDecl::Destroy(ASTContext& C) { // 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 |