<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Apr 23, 2014 at 9:14 PM, Nico Weber <span dir="ltr"><<a href="mailto:nicolasweber@gmx.de" target="_blank">nicolasweber@gmx.de</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: nico<br>
Date: Wed Apr 23 23:14:12 2014<br>
New Revision: 207073<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=207073&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=207073&view=rev</a><br>
Log:<br>
Fix two leaks in c-index-test found by LSan.<br>
<br>
The result of clang_getCursorSpelling() needs to be clang_getCursorSpelling()ed.<br></blockquote><div><br></div><div>*needs to be clang_disposeString()ed.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
Modified:<br>
cfe/trunk/include/clang-c/CXString.h<br>
cfe/trunk/tools/c-index-test/c-index-test.c<br>
<br>
Modified: cfe/trunk/include/clang-c/CXString.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/CXString.h?rev=207073&r1=207072&r2=207073&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/CXString.h?rev=207073&r1=207072&r2=207073&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang-c/CXString.h (original)<br>
+++ cfe/trunk/include/clang-c/CXString.h Wed Apr 23 23:14:12 2014<br>
@@ -31,7 +31,7 @@ extern "C" {<br>
* \brief A character string.<br>
*<br>
* The \c CXString type is used to return strings from the interface when<br>
- * the ownership of that string might different from one call to the next.<br>
+ * the ownership of that string might differ from one call to the next.<br>
* Use \c clang_getCString() to retrieve the string data and, once finished<br>
* with the string data, call \c clang_disposeString() to free the string.<br>
*/<br>
<br>
Modified: cfe/trunk/tools/c-index-test/c-index-test.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=207073&r1=207072&r2=207073&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=207073&r1=207072&r2=207073&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/tools/c-index-test/c-index-test.c (original)<br>
+++ cfe/trunk/tools/c-index-test/c-index-test.c Wed Apr 23 23:14:12 2014<br>
@@ -1333,18 +1333,25 @@ static enum CXChildVisitResult PrintType<br>
}<br>
/* Print the record field offset if applicable. */<br>
{<br>
- const char *FieldName = clang_getCString(clang_getCursorSpelling(cursor));<br>
+ CXString FieldSpelling = clang_getCursorSpelling(cursor);<br>
+ const char *FieldName = clang_getCString(FieldSpelling);<br>
/* recurse to get the root anonymous record parent */<br>
CXCursor Parent, Root;<br>
- if (clang_getCursorKind(cursor) == CXCursor_FieldDecl ) {<br>
- const char *RootParentName;<br>
+ if (clang_getCursorKind(cursor) == CXCursor_FieldDecl) {<br>
+ CXString RootParentSpelling;<br>
+ const char *RootParentName = 0;<br>
Parent = p;<br>
do {<br>
+ if (RootParentName != 0)<br>
+ clang_disposeString(RootParentSpelling);<br>
+<br>
Root = Parent;<br>
- RootParentName = clang_getCString(clang_getCursorSpelling(Root));<br>
+ RootParentSpelling = clang_getCursorSpelling(Root);<br>
+ RootParentName = clang_getCString(RootParentSpelling);<br>
Parent = clang_getCursorSemanticParent(Root);<br>
- } while ( clang_getCursorType(Parent).kind == CXType_Record &&<br>
- !strcmp(RootParentName, "") );<br>
+ } while (clang_getCursorType(Parent).kind == CXType_Record &&<br>
+ !strcmp(RootParentName, ""));<br>
+ clang_disposeString(RootParentSpelling);<br>
/* if RootParentName is "", record is anonymous. */<br>
{<br>
long long Offset = clang_Type_getOffsetOf(clang_getCursorType(Root),<br>
@@ -1352,6 +1359,7 @@ static enum CXChildVisitResult PrintType<br>
printf(" [offsetof=%lld]", Offset);<br>
}<br>
}<br>
+ clang_disposeString(FieldSpelling);<br>
}<br>
/* Print if its a bitfield */<br>
{<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div></div>