@@ -1239,7 +1239,7 @@ unsigned int MidiInCore :: getPortCount()
1239
1239
1240
1240
// This function was submitted by Douglas Casey Tucker and apparently
1241
1241
// derived largely from PortMidi.
1242
- CFStringRef EndpointName ( MIDIEndpointRef endpoint, bool isExternal )
1242
+ CFStringRef CreateEndpointName ( MIDIEndpointRef endpoint, bool isExternal )
1243
1243
{
1244
1244
CFMutableStringRef result = CFStringCreateMutable ( NULL , 0 );
1245
1245
CFStringRef str;
@@ -1249,13 +1249,10 @@ CFStringRef EndpointName( MIDIEndpointRef endpoint, bool isExternal )
1249
1249
MIDIObjectGetStringProperty ( endpoint, kMIDIPropertyName , &str );
1250
1250
if ( str != NULL ) {
1251
1251
CFStringAppend ( result, str );
1252
- CFRelease ( str );
1253
1252
}
1254
1253
1255
1254
// some MIDI devices have a leading space in endpoint name. trim
1256
- CFStringRef space = CFStringCreateWithCString (NULL , " " , kCFStringEncodingUTF8 );
1257
- CFStringTrim (result, space);
1258
- CFRelease (space);
1255
+ CFStringTrim (result, CFSTR (" " ));
1259
1256
1260
1257
MIDIEntityRef entity = 0 ;
1261
1258
MIDIEndpointGetEntity ( endpoint, &entity );
@@ -1269,7 +1266,6 @@ CFStringRef EndpointName( MIDIEndpointRef endpoint, bool isExternal )
1269
1266
MIDIObjectGetStringProperty ( entity, kMIDIPropertyName , &str );
1270
1267
if ( str != NULL ) {
1271
1268
CFStringAppend ( result, str );
1272
- CFRelease ( str );
1273
1269
}
1274
1270
}
1275
1271
// now consider the device's name
@@ -1282,17 +1278,18 @@ CFStringRef EndpointName( MIDIEndpointRef endpoint, bool isExternal )
1282
1278
MIDIObjectGetStringProperty ( device, kMIDIPropertyName , &str );
1283
1279
if ( CFStringGetLength ( result ) == 0 ) {
1284
1280
CFRelease ( result );
1281
+ CFRetain ( str );
1285
1282
return str;
1286
1283
}
1287
1284
if ( str != NULL ) {
1288
1285
// if an external device has only one entity, throw away
1289
1286
// the endpoint name and just use the device name
1290
1287
if ( isExternal && MIDIDeviceGetNumberOfEntities ( device ) < 2 ) {
1291
1288
CFRelease ( result );
1289
+ CFRetain ( str );
1292
1290
return str;
1293
1291
} else {
1294
1292
if ( CFStringGetLength ( str ) == 0 ) {
1295
- CFRelease ( str );
1296
1293
return result;
1297
1294
}
1298
1295
// does the entity name already start with the device name?
@@ -1307,15 +1304,14 @@ CFStringRef EndpointName( MIDIEndpointRef endpoint, bool isExternal )
1307
1304
1308
1305
CFStringInsert ( result, 0 , str );
1309
1306
}
1310
- CFRelease ( str );
1311
1307
}
1312
1308
}
1313
1309
return result;
1314
1310
}
1315
1311
1316
1312
// This function was submitted by Douglas Casey Tucker and apparently
1317
1313
// derived largely from PortMidi.
1318
- static CFStringRef ConnectedEndpointName ( MIDIEndpointRef endpoint )
1314
+ static CFStringRef CreateConnectedEndpointName ( MIDIEndpointRef endpoint )
1319
1315
{
1320
1316
CFMutableStringRef result = CFStringCreateMutable ( NULL , 0 );
1321
1317
CFStringRef str;
@@ -1342,11 +1338,12 @@ static CFStringRef ConnectedEndpointName( MIDIEndpointRef endpoint )
1342
1338
if ( connObjectType == kMIDIObjectType_ExternalSource ||
1343
1339
connObjectType == kMIDIObjectType_ExternalDestination ) {
1344
1340
// Connected to an external device's endpoint (10.3 and later).
1345
- str = EndpointName ( (MIDIEndpointRef)(connObject), true );
1341
+ str = CreateEndpointName ( (MIDIEndpointRef)(connObject), true );
1346
1342
} else {
1347
1343
// Connected to an external device (10.2) (or something else, catch-
1348
1344
str = NULL ;
1349
1345
MIDIObjectGetStringProperty ( connObject, kMIDIPropertyName , &str );
1346
+ if ( str ) CFRetain ( str );
1350
1347
}
1351
1348
if ( str != NULL ) {
1352
1349
if ( anyStrings )
@@ -1367,7 +1364,7 @@ static CFStringRef ConnectedEndpointName( MIDIEndpointRef endpoint )
1367
1364
CFRelease ( result );
1368
1365
1369
1366
// Here, either the endpoint had no connections, or we failed to obtain names
1370
- return EndpointName ( endpoint, false );
1367
+ return CreateEndpointName ( endpoint, false );
1371
1368
}
1372
1369
1373
1370
std::string MidiInCore :: getPortName( unsigned int portNumber )
@@ -1387,7 +1384,7 @@ std::string MidiInCore :: getPortName( unsigned int portNumber )
1387
1384
}
1388
1385
1389
1386
portRef = MIDIGetSource ( portNumber );
1390
- nameRef = ConnectedEndpointName ( portRef );
1387
+ nameRef = CreateConnectedEndpointName ( portRef );
1391
1388
CFStringGetCString ( nameRef, name, sizeof (name), kCFStringEncodingUTF8 );
1392
1389
CFRelease ( nameRef );
1393
1390
@@ -1474,7 +1471,7 @@ std::string MidiOutCore :: getPortName( unsigned int portNumber )
1474
1471
}
1475
1472
1476
1473
portRef = MIDIGetDestination ( portNumber );
1477
- nameRef = ConnectedEndpointName (portRef);
1474
+ nameRef = CreateConnectedEndpointName (portRef);
1478
1475
CFStringGetCString ( nameRef, name, sizeof (name), kCFStringEncodingUTF8 );
1479
1476
CFRelease ( nameRef );
1480
1477
0 commit comments