@@ -1213,28 +1213,34 @@ static void PrintCursor(CXCursor Cursor, const char *CommentSchemaFile) {
1213
1213
}
1214
1214
}
1215
1215
1216
- static const char * GetCursorSource (CXCursor Cursor ) {
1216
+ static CXString createCXString (const char * CS ) {
1217
+ CXString Str ;
1218
+ Str .data = (const void * )CS ;
1219
+ Str .private_flags = 0 ;
1220
+ return Str ;
1221
+ }
1222
+
1223
+ static CXString duplicateCXString (const char * CS ) {
1224
+ CXString Str ;
1225
+ Str .data = strdup (CS );
1226
+ Str .private_flags = 1 ; // CXS_Malloc
1227
+ return Str ;
1228
+ }
1229
+
1230
+ static CXString GetCursorSource (CXCursor Cursor ) {
1217
1231
CXSourceLocation Loc = clang_getCursorLocation (Cursor );
1218
1232
CXString source ;
1219
1233
CXFile file ;
1220
1234
clang_getExpansionLocation (Loc , & file , 0 , 0 , 0 );
1221
1235
source = clang_getFileName (file );
1222
1236
if (!clang_getCString (source )) {
1223
1237
clang_disposeString (source );
1224
- return "<invalid loc>" ;
1238
+ return createCXString ( "<invalid loc>" ) ;
1225
1239
}
1226
- else {
1227
- const char * b = basename (clang_getCString (source ));
1228
- clang_disposeString (source );
1229
- return b ;
1230
- }
1231
- }
1232
-
1233
- static CXString createCXString (const char * CS ) {
1234
- CXString Str ;
1235
- Str .data = (const void * ) CS ;
1236
- Str .private_flags = 0 ;
1237
- return Str ;
1240
+ const char * b = basename (clang_getCString (source ));
1241
+ CXString result = duplicateCXString (b );
1242
+ clang_disposeString (source );
1243
+ return result ;
1238
1244
}
1239
1245
1240
1246
/******************************************************************************/
@@ -1358,8 +1364,10 @@ enum CXChildVisitResult FilteredPrintingVisitor(CXCursor Cursor,
1358
1364
CXSourceLocation Loc = clang_getCursorLocation (Cursor );
1359
1365
unsigned line , column ;
1360
1366
clang_getFileLocation (Loc , 0 , & line , & column , 0 );
1361
- printf ("// %s: %s:%d:%d: " , FileCheckPrefix ,
1362
- GetCursorSource (Cursor ), line , column );
1367
+ CXString source = GetCursorSource (Cursor );
1368
+ printf ("// %s: %s:%d:%d: " , FileCheckPrefix , clang_getCString (source ), line ,
1369
+ column );
1370
+ clang_disposeString (source );
1363
1371
PrintCursor (Cursor , Data -> CommentSchemaFile );
1364
1372
PrintCursorExtent (Cursor );
1365
1373
if (clang_isDeclaration (Cursor .kind )) {
@@ -1428,8 +1436,10 @@ static enum CXChildVisitResult FunctionScanVisitor(CXCursor Cursor,
1428
1436
if (Ref .kind == CXCursor_NoDeclFound ) {
1429
1437
/* Nothing found here; that's fine. */
1430
1438
} else if (Ref .kind != CXCursor_FunctionDecl ) {
1431
- printf ("// %s: %s:%d:%d: " , FileCheckPrefix , GetCursorSource (Ref ),
1432
- curLine , curColumn );
1439
+ CXString CursorSource = GetCursorSource (Ref );
1440
+ printf ("// %s: %s:%d:%d: " , FileCheckPrefix ,
1441
+ clang_getCString (CursorSource ), curLine , curColumn );
1442
+ clang_disposeString (CursorSource );
1433
1443
PrintCursor (Ref , Data -> CommentSchemaFile );
1434
1444
printf ("\n" );
1435
1445
}
@@ -1455,7 +1465,10 @@ enum CXChildVisitResult USRVisitor(CXCursor C, CXCursor parent,
1455
1465
clang_disposeString (USR );
1456
1466
return CXChildVisit_Recurse ;
1457
1467
}
1458
- printf ("// %s: %s %s" , FileCheckPrefix , GetCursorSource (C ), cstr );
1468
+ CXString CursorSource = GetCursorSource (C );
1469
+ printf ("// %s: %s %s" , FileCheckPrefix , clang_getCString (CursorSource ),
1470
+ cstr );
1471
+ clang_disposeString (CursorSource );
1459
1472
1460
1473
PrintCursorExtent (C );
1461
1474
printf ("\n" );
0 commit comments