]> granicus.if.org Git - clang/commitdiff
CIndex: Add temporary hack to leak memory instead of returning invalid pointers.
authorDaniel Dunbar <daniel@zuster.org>
Sun, 8 Nov 2009 04:11:32 +0000 (04:11 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Sun, 8 Nov 2009 04:11:32 +0000 (04:11 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86438 91177308-0d34-0410-b5e6-96231b3b80d8

tools/CIndex/CIndex.cpp
tools/c-index-test/c-index-test.c

index 93891391164c40ac5157d75a897428f9f0f27b1d..1f9be0d0c784c96f26cc90504b8fa3290faea025 100644 (file)
@@ -552,7 +552,8 @@ const char *clang_getDeclSpelling(CXDecl AnonDecl)
   NamedDecl *ND = static_cast<NamedDecl *>(AnonDecl);
   
   if (ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(ND)) {
-    return OMD->getSelector().getAsString().c_str();
+    // FIXME: Memory leak! We need to move to a CXString or other API.
+    return ::strdup(OMD->getSelector().getAsString().c_str());
   }
   if (ObjCCategoryImplDecl *CIMP = dyn_cast<ObjCCategoryImplDecl>(ND))
     // No, this isn't the same as the code below. getIdentifier() is non-virtual
@@ -650,7 +651,8 @@ const char *clang_getCursorSpelling(CXCursor C)
         ObjCMessageExpr *OME = dyn_cast<ObjCMessageExpr>(
                                  static_cast<Stmt *>(C.stmt));
         assert(OME && "clang_getCursorLine(): Missing message expr");
-        return OME->getSelector().getAsString().c_str();
+        // FIXME: Memory leak! We need to move to a CXString or other API.
+        return ::strdup(OME->getSelector().getAsString().c_str());
       }
       case CXCursor_VarRef:
       case CXCursor_FunctionRef:
index 82653357b10f83747ae53483455bc9a036e4f9e0..cc4080e388b5e775c1d64d22c71109b0ef262c00 100644 (file)
@@ -4,6 +4,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <assert.h>
 
 #ifdef _MSC_VER
 char *basename(const char* path)
@@ -86,7 +87,7 @@ static void TranslationUnitVisitor(CXTranslationUnit Unit, CXCursor Cursor,
             printf("// CHECK: %s:%d:%d: ", basename(clang_getCursorSource(Ref)),
                                              curLine, curColumn);
             PrintCursor(Ref);
-            printf(" [Context:%s]\n", clang_getDeclSpelling(Ref.decl));
+                       printf(" [Context:%s]\n", clang_getDeclSpelling(Ref.decl));
           }
           startBuf++;
         }