Browse Source

Tentative fix for unexplained crash

In the presence of multiple raw MIDI devices, libasound crashes
somewhere in snd_config_update (called when opening a device).

I am not sure to understand what causes the problem (it may be
a libasound bug?), but it seems that making sure that
snd_config_update is called only once (by calling it ourselves,
and then using the _lconf-suffixed functions) is enough to
prevent the crash.
develop
Damien Goutte-Gattat 5 years ago
parent
commit
8ce1d04dc7
  1. 20
      src/midi.c

20
src/midi.c

@ -115,6 +115,16 @@ struct midi_io
#ifdef HAVE_ALSA
static int snd_config_updated = 0;
#define SND_CONFIG_UPDATE() \
do { \
if ( ! snd_config_updated ) { \
snd_config_update(); \
snd_config_updated = 1; \
} \
} while ( 0 )
static int
alsa_midi_close(midi_io_t *midi)
{
@ -177,6 +187,8 @@ alsa_midi_open(const char *name)
if ( ! (midi = malloc(sizeof(*midi))) )
return NULL;
SND_CONFIG_UPDATE();
midi->alsa.in = midi->alsa.out = NULL;
midi->error = midi->pos = midi->len = midi->status = 0;
@ -185,8 +197,8 @@ alsa_midi_open(const char *name)
midi->backend.read = alsa_midi_read;
midi->backend.error = alsa_midi_error;
if ( snd_rawmidi_open(&(midi->alsa.in), &(midi->alsa.out), name,
SND_RAWMIDI_NONBLOCK) < 0 ) {
if ( snd_rawmidi_open_lconf(&(midi->alsa.in), &(midi->alsa.out), name,
SND_RAWMIDI_NONBLOCK, snd_config) < 0 ) {
free(midi);
midi = NULL;
}
@ -204,12 +216,14 @@ alsa_midi_get_ports(char ***ports, size_t *n, size_t *max)
char name[32];
int card;
SND_CONFIG_UPDATE();
card = -1;
while ( snd_card_next(&card) >= 0 && card != -1 ) {
snd_ctl_t *ctl;
snprintf(name, sizeof(name), "hw:%d", card);
if ( snd_ctl_open(&ctl, name, 0) >= 0 ) {
if ( snd_ctl_open_lconf(&ctl, name, 0, snd_config) >= 0 ) {
int device;
device = -1;

Loading…
Cancel
Save