r207076 - Fix two leaks found by LSan.

Nico Weber nicolasweber at gmx.de
Wed Apr 23 22:16:45 PDT 2014


Author: nico
Date: Thu Apr 24 00:16:45 2014
New Revision: 207076

URL: http://llvm.org/viewvc/llvm-project?rev=207076&view=rev
Log:
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.

Modified:
    cfe/trunk/tools/libclang/CIndex.cpp

Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=207076&r1=207075&r2=207076&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Thu Apr 24 00:16:45 2014
@@ -6027,14 +6027,21 @@ static int getCursorPlatformAvailability
                                            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 getCursorPlatformAvailability
       if (always_unavailable)
         *always_unavailable = 1;
       if (unavailable_message) {
+        if (DidSetUnavailableMessage)
+          clang_disposeString(*unavailable_message);
         *unavailable_message = cxstring::createDup(Unavailable->getMessage());
+        DidSetUnavailableMessage = true;
       }
       continue;
     }





More information about the cfe-commits mailing list