summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2010-01-21 19:22:34 +0000
committerTed Kremenek <kremenek@apple.com>2010-01-21 19:22:34 +0000
commit819e87379129179b8fef072f81a49cbc752ee58a (patch)
treefa287c6e9ed882828d4fa97da798fa191e9db238 /clang/lib
parent2067816b3ad167a9a6003f9447f9a86a24596739 (diff)
downloadbcm5719-llvm-819e87379129179b8fef072f81a49cbc752ee58a.tar.gz
bcm5719-llvm-819e87379129179b8fef072f81a49cbc752ee58a.zip
Allocate the 'Protocols' array in ObjCInterfaceType and
ObjCObjectPointerType using the allocator associated with ASTContext. Not only does this fix a memory leak, but it also makes these arrays BumpPtrAllocated (in the typical case). llvm-svn: 94090
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/AST/ASTContext.cpp5
-rw-r--r--clang/lib/AST/Type.cpp39
2 files changed, 42 insertions, 2 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index f8fc626457a..c1bc70989d4 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -2127,7 +2127,8 @@ QualType ASTContext::getObjCObjectPointerType(QualType InterfaceT,
// No Match;
ObjCObjectPointerType *QType = new (*this, TypeAlignment)
- ObjCObjectPointerType(Canonical, InterfaceT, Protocols, NumProtocols);
+ ObjCObjectPointerType(*this, Canonical, InterfaceT, Protocols,
+ NumProtocols);
Types.push_back(QType);
ObjCObjectPointerTypes.InsertNode(QType, InsertPos);
@@ -2161,7 +2162,7 @@ QualType ASTContext::getObjCInterfaceType(const ObjCInterfaceDecl *Decl,
}
ObjCInterfaceType *QType = new (*this, TypeAlignment)
- ObjCInterfaceType(Canonical, const_cast<ObjCInterfaceDecl*>(Decl),
+ ObjCInterfaceType(*this, Canonical, const_cast<ObjCInterfaceDecl*>(Decl),
Protocols, NumProtocols);
Types.push_back(QType);
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index e0055f18782..edfb580cc35 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -339,6 +339,25 @@ const RecordType *Type::getAsUnionType() const {
return 0;
}
+ObjCInterfaceType::ObjCInterfaceType(ASTContext &Ctx, QualType Canonical,
+ ObjCInterfaceDecl *D,
+ ObjCProtocolDecl **Protos, unsigned NumP) :
+ Type(ObjCInterface, Canonical, /*Dependent=*/false),
+ Decl(D), Protocols(0), NumProtocols(NumP)
+{
+ if (NumProtocols) {
+ Protocols = new (Ctx) ObjCProtocolDecl*[NumProtocols];
+ memcpy(Protocols, Protos, NumProtocols * sizeof(*Protocols));
+ }
+}
+
+void ObjCInterfaceType::Destroy(ASTContext& C) {
+ if (Protocols)
+ C.Deallocate(Protocols);
+ this->~ObjCInterfaceType();
+ C.Deallocate(this);
+}
+
const ObjCInterfaceType *Type::getAsObjCQualifiedInterfaceType() const {
// There is no sugar for ObjCInterfaceType's, just return the canonical
// type pointer if it is the right class. There is no typedef information to
@@ -353,6 +372,26 @@ bool Type::isObjCQualifiedInterfaceType() const {
return getAsObjCQualifiedInterfaceType() != 0;
}
+ObjCObjectPointerType::ObjCObjectPointerType(ASTContext &Ctx,
+ QualType Canonical, QualType T,
+ ObjCProtocolDecl **Protos,
+ unsigned NumP) :
+ Type(ObjCObjectPointer, Canonical, /*Dependent=*/false),
+ PointeeType(T), Protocols(NULL), NumProtocols(NumP)
+{
+ if (NumProtocols) {
+ Protocols = new (Ctx) ObjCProtocolDecl*[NumProtocols];
+ memcpy(Protocols, Protos, NumProtocols * sizeof(*Protocols));
+ }
+}
+
+void ObjCObjectPointerType::Destroy(ASTContext& C) {
+ if (Protocols)
+ C.Deallocate(Protocols);
+ this->~ObjCObjectPointerType();
+ C.Deallocate(this);
+}
+
const ObjCObjectPointerType *Type::getAsObjCQualifiedIdType() const {
// There is no sugar for ObjCQualifiedIdType's, just return the canonical
// type pointer if it is the right class.
OpenPOWER on IntegriCloud