BR: MidiOutput::createNewDeviceleaks devices if you use the same name twice

MidiOutput::createNewDeviceleaks devices if you use the same name twice.

    o1 = juce::MidiOutput::createNewDevice ("Command8 Port 1");
    o2 = juce::MidiOutput::createNewDevice ("Command8 Port 1");

The second call returns nullptr but the MIDI port is created, and there is no way to shut it down now (except exit the process).

Which platform are you seeing this on? I don’t get this behaviour on Big Sur.

I’m on Big Sur as well. What I am seeing is:

auto err = CreatorFunctionsToUse::createSource (ump::PacketProtocol::MIDI_1_0, client, name.cfString, &endpoint);

This succeeds and creates a new midi port and places it in endpoint

if (! CHECK_ERROR (MIDIObjectSetIntegerProperty (endpoint, kMIDIPropertyUniqueID, (SInt32) deviceIdentifier)))

This fails, because the ID isn’t unique. And then the function bails out, leaking the endpoint

My “fix” to get me up and running:

        for (int i = 0; i < 10; i++)
        {
            if (CHECK_ERROR (MIDIObjectSetIntegerProperty (endpoint, kMIDIPropertyUniqueID, (SInt32) deviceIdentifier + i)))
                break;

            if (i == 9)
                return {};
        }

I’m not sure if you actually want to allow multiple MIDI devices with the same name. I had another program that failed when accessing ports with the same name, so I was just creating a quick test program to generate the ports, since I don’t have two of the same midi devices. I was surprised to see the two ports in the other program, yet get a nullptr for the second device in juce.

Thanks for providing more details. I still can’t reproduce the issue by creating multiple devices with the same name (Big Sur Beta 11.3) but I can see how endpoints/ports might be leaked if an error is emitted during initialisation of a MidiInput or MidiOutput.

I’ve added a potential fix for the issue here:

Please let me know if this patch doesn’t resolve the issue for you, and I’ll take another look.

1 Like