]> granicus.if.org Git - clang/commitdiff
Fix two leaks found by LSan.
authorNico Weber <nicolasweber@gmx.de>
Thu, 24 Apr 2014 05:16:45 +0000 (05:16 +0000)
committerNico Weber <nicolasweber@gmx.de>
Thu, 24 Apr 2014 05:16:45 +0000 (05:16 +0000)
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

tools/libclang/CIndex.cpp

index 9d59fa7c7b5ba7edeeda7cf6ec9cb16ce8f1a386..25f53c4f3d64bd073feb8bf8c16b13a40741a329 100644 (file)
@@ -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<DeprecatedAttr>(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;
     }