fix some segfaults

This commit is contained in:
Neale Pickett 2013-05-27 14:54:27 -06:00
parent 46e3d5ce71
commit a843d39b79
1 changed files with 16 additions and 9 deletions

23
hdjd.c
View File

@ -74,24 +74,30 @@ usb_xfer_done(struct libusb_transfer *transfer)
void
handle_alsa()
{
snd_midi_event_t *midi_event_parser;
static snd_midi_event_t *midi_event_parser = NULL;
snd_seq_event_t *ev;
int ret = 1;
for (ret = 1; ret > 0; ) {
char buf[512];
DUMP();
for (;;) {
char buf[256];
long converted;
int i;
ret = snd_seq_event_input(handle, &ev);
snd_midi_event_new(512, &midi_event_parser);
converted = snd_midi_event_decode(midi_event_parser, buf, 512, ev);
if (snd_seq_event_input(handle, &ev) < 0) {
break;
}
if (! midi_event_parser) {
if (snd_midi_event_new(256, &midi_event_parser) < 0) {
continue;
}
}
converted = snd_midi_event_decode(midi_event_parser, buf, 256, ev);
printf(" << ");
for (i = 0; i < converted; i += 1) {
printf("%02x ", buf[i]);
}
printf("\n");
snd_midi_event_free(midi_event_parser);
printf(":\n");
}
}
@ -224,6 +230,7 @@ main(int argc, char **argv)
}
ret = select(nfds + 1, &rfds, &wfds, NULL, timeout);
DUMP_d(rfds);
for (i = 0; usb_fds[i]; i += 1) {
int fd = usb_fds[i]->fd;