summaryrefslogtreecommitdiffstats
path: root/sys/dev/sound
diff options
context:
space:
mode:
authoravatar <avatar@FreeBSD.org>2015-11-17 15:20:12 +0000
committeravatar <avatar@FreeBSD.org>2015-11-17 15:20:12 +0000
commite1a245c4b6e5d7c7044bdf86c8edb4a380bd3fbb (patch)
tree91bf6884ead2802e9a1a08c79e2fc6e40fb0793d /sys/dev/sound
parentc67545fc86b9f40cecc9349531138904be6df511 (diff)
downloadFreeBSD-src-e1a245c4b6e5d7c7044bdf86c8edb4a380bd3fbb.zip
FreeBSD-src-e1a245c4b6e5d7c7044bdf86c8edb4a380bd3fbb.tar.gz
MFC r289888:
- Plugging a memory leak when malloc() failed during initialisation; - Plugging another memory leak inside the destructor. Reviewed by: matk
Diffstat (limited to 'sys/dev/sound')
-rw-r--r--sys/dev/sound/midi/midi.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/sys/dev/sound/midi/midi.c b/sys/dev/sound/midi/midi.c
index f95218b..e741dd0d 100644
--- a/sys/dev/sound/midi/midi.c
+++ b/sys/dev/sound/midi/midi.c
@@ -319,6 +319,8 @@ midi_init(kobj_class_t cls, int unit, int channel, void *cookie)
goto err0;
m->synth = malloc(sizeof(*m->synth), M_MIDI, M_NOWAIT | M_ZERO);
+ if (m->synth == NULL)
+ goto err1;
kobj_init((kobj_t)m->synth, &midisynth_class);
m->synth->m = m;
kobj_init((kobj_t)m, cls);
@@ -327,7 +329,7 @@ midi_init(kobj_class_t cls, int unit, int channel, void *cookie)
MIDI_DEBUG(1, printf("midiinit queues %d/%d.\n", inqsize, outqsize));
if (!inqsize && !outqsize)
- goto err1;
+ goto err2;
mtx_init(&m->lock, "raw midi", NULL, 0);
mtx_init(&m->qlock, "q raw midi", NULL, 0);
@@ -352,7 +354,7 @@ midi_init(kobj_class_t cls, int unit, int channel, void *cookie)
if ((inqsize && !MIDIQ_BUF(m->inq)) ||
(outqsize && !MIDIQ_BUF(m->outq)))
- goto err2;
+ goto err3;
m->busy = 0;
@@ -362,7 +364,7 @@ midi_init(kobj_class_t cls, int unit, int channel, void *cookie)
m->cookie = cookie;
if (MPU_INIT(m, cookie))
- goto err2;
+ goto err3;
mtx_unlock(&m->lock);
mtx_unlock(&m->qlock);
@@ -378,13 +380,14 @@ midi_init(kobj_class_t cls, int unit, int channel, void *cookie)
return m;
-err2: mtx_destroy(&m->qlock);
+err3: mtx_destroy(&m->qlock);
mtx_destroy(&m->lock);
if (MIDIQ_BUF(m->inq))
free(MIDIQ_BUF(m->inq), M_MIDI);
if (MIDIQ_BUF(m->outq))
free(MIDIQ_BUF(m->outq), M_MIDI);
+err2: free(m->synth, M_MIDI);
err1: free(m, M_MIDI);
err0: mtx_unlock(&midistat_lock);
MIDI_DEBUG(1, printf("midi_init ended in error\n"));
@@ -1388,6 +1391,7 @@ midi_destroy(struct snd_midi *m, int midiuninit)
free(MIDIQ_BUF(m->outq), M_MIDI);
mtx_destroy(&m->qlock);
mtx_destroy(&m->lock);
+ free(m->synth, M_MIDI);
free(m, M_MIDI);
return 0;
}
OpenPOWER on IntegriCloud