midi: Free ALSA seq resources in midi_device_remove()
authorJacek Konieczny <jajcus@jajcus.net>
Mon, 1 Nov 2021 13:49:18 +0000 (14:49 +0100)
committerAyush Garg <ayush.garg@samsung.com>
Fri, 11 Mar 2022 13:38:37 +0000 (19:08 +0530)
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 <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
profiles/midi/midi.c

index 737d1b5..40064df 100644 (file)
@@ -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);
 }