From: Nico Weber Date: Thu, 24 Apr 2014 05:16:45 +0000 (+0000) Subject: Fix two leaks found by LSan. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4674f25eb2d99d333bbcc67dc2f6b2ae84690467;p=clang Fix two leaks found by LSan. A CursorPlatformAvailability can have several "unavailable" attributes, don't leak all but the first. I'm not sure if there can be several "deprecate"ds too, but add the same logic there to keep the two code paths looking the same. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@207076 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index 9d59fa7c7b..25f53c4f3d 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -6027,14 +6027,21 @@ static int getCursorPlatformAvailabilityForDecl(const Decl *D, CXPlatformAvailability *availability, int availability_size) { bool HadAvailAttr = false; + bool DidSetDeprecatedMessage = false; + bool DidSetUnavailableMessage = false; + int N = 0; for (auto A : D->attrs()) { if (DeprecatedAttr *Deprecated = dyn_cast(A)) { HadAvailAttr = true; if (always_deprecated) *always_deprecated = 1; - if (deprecated_message) + if (deprecated_message) { + if (DidSetDeprecatedMessage) + clang_disposeString(*deprecated_message); *deprecated_message = cxstring::createDup(Deprecated->getMessage()); + DidSetDeprecatedMessage = true; + } continue; } @@ -6043,7 +6050,10 @@ static int getCursorPlatformAvailabilityForDecl(const Decl *D, if (always_unavailable) *always_unavailable = 1; if (unavailable_message) { + if (DidSetUnavailableMessage) + clang_disposeString(*unavailable_message); *unavailable_message = cxstring::createDup(Unavailable->getMessage()); + DidSetUnavailableMessage = true; } continue; }