From: Nico Weber Date: Thu, 24 Apr 2014 04:14:12 +0000 (+0000) Subject: Fix two leaks in c-index-test found by LSan. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=29c13d16f0d3a3a287a2b549b107e90085c0a458;p=clang Fix two leaks in c-index-test found by LSan. The result of clang_getCursorSpelling() needs to be clang_getCursorSpelling()ed. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@207073 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang-c/CXString.h b/include/clang-c/CXString.h index 592c4dc44e..cf198cbf5d 100644 --- a/include/clang-c/CXString.h +++ b/include/clang-c/CXString.h @@ -31,7 +31,7 @@ extern "C" { * \brief A character string. * * The \c CXString type is used to return strings from the interface when - * the ownership of that string might different from one call to the next. + * the ownership of that string might differ from one call to the next. * Use \c clang_getCString() to retrieve the string data and, once finished * with the string data, call \c clang_disposeString() to free the string. */ diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c index 461765c13a..aec5f1bd64 100644 --- a/tools/c-index-test/c-index-test.c +++ b/tools/c-index-test/c-index-test.c @@ -1333,18 +1333,25 @@ static enum CXChildVisitResult PrintTypeSize(CXCursor cursor, CXCursor p, } /* Print the record field offset if applicable. */ { - const char *FieldName = clang_getCString(clang_getCursorSpelling(cursor)); + CXString FieldSpelling = clang_getCursorSpelling(cursor); + const char *FieldName = clang_getCString(FieldSpelling); /* recurse to get the root anonymous record parent */ CXCursor Parent, Root; - if (clang_getCursorKind(cursor) == CXCursor_FieldDecl ) { - const char *RootParentName; + if (clang_getCursorKind(cursor) == CXCursor_FieldDecl) { + CXString RootParentSpelling; + const char *RootParentName = 0; Parent = p; do { + if (RootParentName != 0) + clang_disposeString(RootParentSpelling); + Root = Parent; - RootParentName = clang_getCString(clang_getCursorSpelling(Root)); + RootParentSpelling = clang_getCursorSpelling(Root); + RootParentName = clang_getCString(RootParentSpelling); Parent = clang_getCursorSemanticParent(Root); - } while ( clang_getCursorType(Parent).kind == CXType_Record && - !strcmp(RootParentName, "") ); + } while (clang_getCursorType(Parent).kind == CXType_Record && + !strcmp(RootParentName, "")); + clang_disposeString(RootParentSpelling); /* if RootParentName is "", record is anonymous. */ { long long Offset = clang_Type_getOffsetOf(clang_getCursorType(Root), @@ -1352,6 +1359,7 @@ static enum CXChildVisitResult PrintTypeSize(CXCursor cursor, CXCursor p, printf(" [offsetof=%lld]", Offset); } } + clang_disposeString(FieldSpelling); } /* Print if its a bitfield */ {