⬢ DragonFlyBSD Kernel Audit
DF-4284 / fix.diff
← back to finding ↓ download raw
--- a/sys/dev/sound/midi/midi.c
+++ b/sys/dev/sound/midi/midi.c
@@ -1457,6 +1457,7 @@ midi_load(void)
 static int
 midi_unload(void)
 {
+	struct snd_midi *mnext;
 	struct snd_midi *m;
 	int retval;
 
@@ -1468,9 +1469,10 @@ midi_unload(void)
 	if (midistat_isopen)
 		goto exit0;
 
-	TAILQ_FOREACH(m, &midi_devs, link) {
+	for (m = TAILQ_FIRST(&midi_devs); m != NULL; m = mnext) {
+		mnext = TAILQ_NEXT(m, link);	/* stash: midi_destroy frees m */
 		lockmgr(&m->lock, LK_EXCLUSIVE);
 		if (m->busy)
 			retval = EBUSY;
 		else
 			retval = midi_destroy(m, 1);
 		if (retval)
 			goto exit1;
 	}