From eea72da77bc6aa3a3ef886e237cfbb9608d63485 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Tue, 7 Sep 2021 23:30:44 +0600 Subject: [PATCH] Fix NULL access crashes on ALSA MIDI close --- src/unix/linux_midi_alsa.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/unix/linux_midi_alsa.c b/src/unix/linux_midi_alsa.c index 2b771f81c..e3b009d6d 100644 --- a/src/unix/linux_midi_alsa.c +++ b/src/unix/linux_midi_alsa.c @@ -298,14 +298,17 @@ void plat_midi_input_init(void) void plat_midi_input_close(void) { - thread_wait_mutex(midiinmtx); + if (midiinmtx) thread_wait_mutex(midiinmtx); if (midiin != NULL) { snd_rawmidi_close(midiin); midiin = NULL; } - thread_release_mutex(midiinmtx); - thread_close_mutex(midiinmtx); + if (midiinmtx) + { + thread_release_mutex(midiinmtx); + thread_close_mutex(midiinmtx); + } midiinmtx = NULL; }