From b196ca51f0ebb98e1c5a19e25622a0f42b08ca6c Mon Sep 17 00:00:00 2001 From: Jacek Konieczny Date: Mon, 1 Nov 2021 14:49:18 +0100 Subject: [PATCH] midi: Free ALSA seq resources in midi_device_remove() Sometimes, on connection error, this gets called and frees the device when midi_disconnect() was not called which would leave ALSA sequencer objects leaking. Signed-off-by: Anuj Jain Signed-off-by: Ayush Garg --- profiles/midi/midi.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/profiles/midi/midi.c b/profiles/midi/midi.c index 737d1b5..40064df 100644 --- a/profiles/midi/midi.c +++ b/profiles/midi/midi.c @@ -255,6 +255,15 @@ static void midi_device_remove(struct btd_service *service) return; } + if (midi->seq_handle) { + midi_read_free(&midi->midi_in); + midi_write_free(&midi->midi_out); + io_destroy(midi->io); + snd_seq_delete_simple_port(midi->seq_handle, midi->seq_port_id); + midi->seq_port_id = 0; + snd_seq_close(midi->seq_handle); + } + btd_device_unref(midi->dev); g_free(midi); } -- 2.7.4