diff options
author | Ted Kremenek <kremenek@apple.com> | 2010-01-21 19:22:34 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2010-01-21 19:22:34 +0000 |
commit | 71842cc07aafdebc9b180322ebb46f530beca5d6 (patch) | |
tree | fcd0770ae5a35c741b83fb53df3931187c3f8dac /lib/AST/Type.cpp | |
parent | 5bb4d982230f36e6e374ea6ac83f31011a8d0a6b (diff) |
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).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94090 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/Type.cpp')
-rw-r--r-- | lib/AST/Type.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index e0055f1878..edfb580cc3 100644 --- a/lib/AST/Type.cpp +++ b/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. |