Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1761372AbXHGJoS (ORCPT ); Tue, 7 Aug 2007 05:44:18 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1758133AbXHGJoA (ORCPT ); Tue, 7 Aug 2007 05:44:00 -0400 Received: from cantor2.suse.de ([195.135.220.15]:46247 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757733AbXHGJn7 (ORCPT ); Tue, 7 Aug 2007 05:43:59 -0400 Date: Tue, 07 Aug 2007 11:43:58 +0200 Message-ID: From: Takashi Iwai To: Eugene Teo Cc: linux-kernel@vger.kernel.org Subject: Re: [ALSA] seq: resource leak fix and various code cleanups In-Reply-To: <20070807084048.GA5205@kernel.sg> References: <20070807084048.GA5205@kernel.sg> User-Agent: Wanderlust/2.15.5 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.7 (=?ISO-8859-4?Q?Sanj=F2?=) APEL/10.6 MULE XEmacs/21.5 (beta27) (fiddleheads) (+CVS-20060704) (i386-suse-linux) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2069 Lines: 68 At Tue, 7 Aug 2007 16:40:48 +0800, Eugene Teo wrote: > > This patch fixes: > 1) a resource leak (CID: 1817) > 2) various code cleanups > > Signed-off-by: Eugene Teo > --- > sound/core/seq/oss/seq_oss_init.c | 29 ++++++++++++++++++----------- > sound/core/seq/oss/seq_oss_writeq.c | 6 ++++-- > 2 files changed, 22 insertions(+), 13 deletions(-) > > diff --git a/sound/core/seq/oss/seq_oss_init.c b/sound/core/seq/oss/seq_oss_init.c > index ca5a2ed..c9b95c3 100644 > --- a/sound/core/seq/oss/seq_oss_init.c > +++ b/sound/core/seq/oss/seq_oss_init.c > @@ -176,7 +176,8 @@ snd_seq_oss_open(struct file *file, int level) > int i, rc; > struct seq_oss_devinfo *dp; > > - if ((dp = kzalloc(sizeof(*dp), GFP_KERNEL)) == NULL) { > + dp = kzalloc(sizeof(*dp), GFP_KERNEL); > + if (dp == NULL) { Better to use "if (!dp)" > snd_printk(KERN_ERR "can't malloc device info\n"); > return -ENOMEM; > } > @@ -188,8 +189,8 @@ snd_seq_oss_open(struct file *file, int level) > } > if (i >= SNDRV_SEQ_OSS_MAX_CLIENTS) { > snd_printk(KERN_ERR "too many applications\n"); > - kfree(dp); > - return -ENOMEM; > + rc = -ENOMEM; > + goto _error; This seems wrong. It goes before initializing dp->queue = -1, so it screws up delete_seq_queue(). > @@ -276,11 +281,13 @@ snd_seq_oss_open(struct file *file, int level) > return 0; > > _error: > - snd_seq_oss_synth_cleanup(dp); > - snd_seq_oss_midi_cleanup(dp); > - i = dp->queue; > + snd_seq_oss_writeq_delete(dp->writeq); > + snd_seq_oss_readq_delete(dp->readq); > + delete_seq_queue(dp->queue); > delete_port(dp); > - delete_seq_queue(i); > + snd_seq_oss_midi_cleanup(dp); > + snd_seq_oss_synth_cleanup(dp); > + kfree(dp); The order of these calls is important. Did you test it and confirm that it has no side effects? Takashi - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/