r207073 - Fix two leaks in c-index-test found by LSan.

Nico Weber thakis at chromium.org
Wed Apr 23 21:57:24 PDT 2014


On Wed, Apr 23, 2014 at 9:14 PM, Nico Weber <nicolasweber at gmx.de> wrote:

> Author: nico
> Date: Wed Apr 23 23:14:12 2014
> New Revision: 207073
>
> URL: http://llvm.org/viewvc/llvm-project?rev=207073&view=rev
> Log:
> Fix two leaks in c-index-test found by LSan.
>
> The result of clang_getCursorSpelling() needs to be
> clang_getCursorSpelling()ed.
>

*needs to be clang_disposeString()ed.


>
> Modified:
>     cfe/trunk/include/clang-c/CXString.h
>     cfe/trunk/tools/c-index-test/c-index-test.c
>
> Modified: cfe/trunk/include/clang-c/CXString.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/CXString.h?rev=207073&r1=207072&r2=207073&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang-c/CXString.h (original)
> +++ cfe/trunk/include/clang-c/CXString.h Wed Apr 23 23:14:12 2014
> @@ -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.
>   */
>
> Modified: cfe/trunk/tools/c-index-test/c-index-test.c
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=207073&r1=207072&r2=207073&view=diff
>
> ==============================================================================
> --- cfe/trunk/tools/c-index-test/c-index-test.c (original)
> +++ cfe/trunk/tools/c-index-test/c-index-test.c Wed Apr 23 23:14:12 2014
> @@ -1333,18 +1333,25 @@ static enum CXChildVisitResult PrintType
>    }
>    /* 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 PrintType
>          printf(" [offsetof=%lld]", Offset);
>        }
>      }
> +    clang_disposeString(FieldSpelling);
>    }
>    /* Print if its a bitfield */
>    {
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140423/1135458f/attachment.html>


More information about the cfe-commits mailing list