From: Daniel Dunbar Date: Sun, 8 Nov 2009 04:11:32 +0000 (+0000) Subject: CIndex: Add temporary hack to leak memory instead of returning invalid pointers. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4dc99f8928f0d21b15edccb03dbc9492a1ba87f7;p=clang CIndex: Add temporary hack to leak memory instead of returning invalid pointers. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86438 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/tools/CIndex/CIndex.cpp b/tools/CIndex/CIndex.cpp index 9389139116..1f9be0d0c7 100644 --- a/tools/CIndex/CIndex.cpp +++ b/tools/CIndex/CIndex.cpp @@ -552,7 +552,8 @@ const char *clang_getDeclSpelling(CXDecl AnonDecl) NamedDecl *ND = static_cast(AnonDecl); if (ObjCMethodDecl *OMD = dyn_cast(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(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( static_cast(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: diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c index 82653357b1..cc4080e388 100644 --- a/tools/c-index-test/c-index-test.c +++ b/tools/c-index-test/c-index-test.c @@ -4,6 +4,7 @@ #include #include #include +#include #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++; }