@@ -1179,7 +1179,7 @@ unsigned int MidiInCore :: getPortCount()
1179
1179
1180
1180
// This function was submitted by Douglas Casey Tucker and apparently
1181
1181
// derived largely from PortMidi.
1182
- CFStringRef EndpointName ( MIDIEndpointRef endpoint, bool isExternal )
1182
+ CFStringRef CreateEndpointName ( MIDIEndpointRef endpoint, bool isExternal )
1183
1183
{
1184
1184
CFMutableStringRef result = CFStringCreateMutable ( NULL , 0 );
1185
1185
CFStringRef str;
@@ -1189,13 +1189,10 @@ CFStringRef EndpointName( MIDIEndpointRef endpoint, bool isExternal )
1189
1189
MIDIObjectGetStringProperty ( endpoint, kMIDIPropertyName , &str );
1190
1190
if ( str != NULL ) {
1191
1191
CFStringAppend ( result, str );
1192
- CFRelease ( str );
1193
1192
}
1194
1193
1195
1194
// some MIDI devices have a leading space in endpoint name. trim
1196
- CFStringRef space = CFStringCreateWithCString (NULL , " " , kCFStringEncodingUTF8 );
1197
- CFStringTrim (result, space);
1198
- CFRelease (space);
1195
+ CFStringTrim (result, CFSTR (" " ));
1199
1196
1200
1197
MIDIEntityRef entity = 0 ;
1201
1198
MIDIEndpointGetEntity ( endpoint, &entity );
@@ -1209,7 +1206,6 @@ CFStringRef EndpointName( MIDIEndpointRef endpoint, bool isExternal )
1209
1206
MIDIObjectGetStringProperty ( entity, kMIDIPropertyName , &str );
1210
1207
if ( str != NULL ) {
1211
1208
CFStringAppend ( result, str );
1212
- CFRelease ( str );
1213
1209
}
1214
1210
}
1215
1211
// now consider the device's name
@@ -1222,17 +1218,18 @@ CFStringRef EndpointName( MIDIEndpointRef endpoint, bool isExternal )
1222
1218
MIDIObjectGetStringProperty ( device, kMIDIPropertyName , &str );
1223
1219
if ( CFStringGetLength ( result ) == 0 ) {
1224
1220
CFRelease ( result );
1221
+ CFRetain ( str );
1225
1222
return str;
1226
1223
}
1227
1224
if ( str != NULL ) {
1228
1225
// if an external device has only one entity, throw away
1229
1226
// the endpoint name and just use the device name
1230
1227
if ( isExternal && MIDIDeviceGetNumberOfEntities ( device ) < 2 ) {
1231
1228
CFRelease ( result );
1229
+ CFRetain ( str );
1232
1230
return str;
1233
1231
} else {
1234
1232
if ( CFStringGetLength ( str ) == 0 ) {
1235
- CFRelease ( str );
1236
1233
return result;
1237
1234
}
1238
1235
// does the entity name already start with the device name?
@@ -1247,15 +1244,14 @@ CFStringRef EndpointName( MIDIEndpointRef endpoint, bool isExternal )
1247
1244
1248
1245
CFStringInsert ( result, 0 , str );
1249
1246
}
1250
- CFRelease ( str );
1251
1247
}
1252
1248
}
1253
1249
return result;
1254
1250
}
1255
1251
1256
1252
// This function was submitted by Douglas Casey Tucker and apparently
1257
1253
// derived largely from PortMidi.
1258
- static CFStringRef ConnectedEndpointName ( MIDIEndpointRef endpoint )
1254
+ static CFStringRef CreateConnectedEndpointName ( MIDIEndpointRef endpoint )
1259
1255
{
1260
1256
CFMutableStringRef result = CFStringCreateMutable ( NULL , 0 );
1261
1257
CFStringRef str;
@@ -1282,11 +1278,12 @@ static CFStringRef ConnectedEndpointName( MIDIEndpointRef endpoint )
1282
1278
if ( connObjectType == kMIDIObjectType_ExternalSource ||
1283
1279
connObjectType == kMIDIObjectType_ExternalDestination ) {
1284
1280
// Connected to an external device's endpoint (10.3 and later).
1285
- str = EndpointName ( (MIDIEndpointRef)(connObject), true );
1281
+ str = CreateEndpointName ( (MIDIEndpointRef)(connObject), true );
1286
1282
} else {
1287
1283
// Connected to an external device (10.2) (or something else, catch-
1288
1284
str = NULL ;
1289
1285
MIDIObjectGetStringProperty ( connObject, kMIDIPropertyName , &str );
1286
+ if ( str ) CFRetain ( str );
1290
1287
}
1291
1288
if ( str != NULL ) {
1292
1289
if ( anyStrings )
@@ -1307,7 +1304,7 @@ static CFStringRef ConnectedEndpointName( MIDIEndpointRef endpoint )
1307
1304
CFRelease ( result );
1308
1305
1309
1306
// Here, either the endpoint had no connections, or we failed to obtain names
1310
- return EndpointName ( endpoint, false );
1307
+ return CreateEndpointName ( endpoint, false );
1311
1308
}
1312
1309
1313
1310
std::string MidiInCore :: getPortName( unsigned int portNumber )
@@ -1327,7 +1324,7 @@ std::string MidiInCore :: getPortName( unsigned int portNumber )
1327
1324
}
1328
1325
1329
1326
portRef = MIDIGetSource ( portNumber );
1330
- nameRef = ConnectedEndpointName ( portRef );
1327
+ nameRef = CreateConnectedEndpointName ( portRef );
1331
1328
CFStringGetCString ( nameRef, name, sizeof (name), kCFStringEncodingUTF8 );
1332
1329
CFRelease ( nameRef );
1333
1330
@@ -1414,7 +1411,7 @@ std::string MidiOutCore :: getPortName( unsigned int portNumber )
1414
1411
}
1415
1412
1416
1413
portRef = MIDIGetDestination ( portNumber );
1417
- nameRef = ConnectedEndpointName (portRef);
1414
+ nameRef = CreateConnectedEndpointName (portRef);
1418
1415
CFStringGetCString ( nameRef, name, sizeof (name), kCFStringEncodingUTF8 );
1419
1416
CFRelease ( nameRef );
1420
1417
0 commit comments