From owner-svn-src-stable-10@freebsd.org Tue Nov 17 15:20:13 2015 Return-Path: Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 95EF3A3041F; Tue, 17 Nov 2015 15:20:13 +0000 (UTC) (envelope-from avatar@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 413451157; Tue, 17 Nov 2015 15:20:13 +0000 (UTC) (envelope-from avatar@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id tAHFKCN8054512; Tue, 17 Nov 2015 15:20:12 GMT (envelope-from avatar@FreeBSD.org) Received: (from avatar@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id tAHFKCBJ054511; Tue, 17 Nov 2015 15:20:12 GMT (envelope-from avatar@FreeBSD.org) Message-Id: <201511171520.tAHFKCBJ054511@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: avatar set sender to avatar@FreeBSD.org using -f From: Tai-hwa Liang Date: Tue, 17 Nov 2015 15:20:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r290988 - stable/10/sys/dev/sound/midi X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 17 Nov 2015 15:20:13 -0000 Author: avatar Date: Tue Nov 17 15:20:12 2015 New Revision: 290988 URL: https://svnweb.freebsd.org/changeset/base/290988 Log: MFC r289888: - Plugging a memory leak when malloc() failed during initialisation; - Plugging another memory leak inside the destructor. Reviewed by: matk Modified: stable/10/sys/dev/sound/midi/midi.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/sound/midi/midi.c ============================================================================== --- stable/10/sys/dev/sound/midi/midi.c Tue Nov 17 15:18:59 2015 (r290987) +++ stable/10/sys/dev/sound/midi/midi.c Tue Nov 17 15:20:12 2015 (r290988) @@ -319,6 +319,8 @@ midi_init(kobj_class_t cls, int unit, in 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, in 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, in 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, in 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, in 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 mid 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; }