ALSA MIDI preferences with zero MIDI devices make purr-data crash with a segfault
To reproduce: Launch purr-data on Linux (tested on Arch) with:
pd-l2ork -alsamidi -mididev 0. Launch the Preferences dialog with Ctrl+P. Press Apply twice => segfault in snd_seq_close.
#0 0x00007ffff7b72862 in snd_seq_close () from /usr/lib/libasound.so.2 #1 0x00000000005125f9 in sys_alsa_close_midi () at s_midi_alsa.c:223 #2 0x00000000004af64d in glob_midi_dialog (dummy=<optimized out>, s=<optimized out>, argc=<optimized out>, argv=0x7fffffffe320) at s_midi.c:864 #3 0x0000000000494388 in pd_typedmess (x=x@entry=0xb592f8 <glob_pdobject>, s=0xc3fb80, argc=argc@entry=10, argv=argv@entry=0x7fffffffe320) at m_class.c:782 #4 0x000000000049d006 in binbuf_eval (x=<optimized out>, target=0xb592f8 <glob_pdobject>, target@entry=0x0, argc=argc@entry=0, argv=argv@entry=0x0) at m_binbuf.c:904 #5 0x00000000004a3c5c in socketreceiver_read (x=0xc7a220, fd=28) at s_inter.c:570 #6 0x00000000004a2f9b in sys_domicrosleep (microsec=microsec@entry=0, pollem=1) at s_inter.c:208 #7 0x00000000004a591b in sys_pollgui () at s_inter.c:1110 #8 0x00000000004a002b in m_pollingscheduler () at m_sched.c:542 #9 m_mainloop () at m_sched.c:622 #10 0x00000000004a29fb in sys_main (argc=<optimized out>, argv=<optimized out>) at s_main.c:344 #11 0x00007ffff63bb291 in __libc_start_main () from /usr/lib/libc.so.6 #12 0x0000000000417d2a in _start ()
Obviously sys_alsa_close_midi tries to close a non-existent ALSA MIDI device handle there. The root cause seems to be that the ALSA MIDI driver doesn't keep track of how many MIDI devices it has open. It even says so in the code comments, but apparently that never got fixed. I'm looking at that borked code now. Will also check whether this has already been fixed in vanilla at some point.