Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755413Ab0BXHLL (ORCPT ); Wed, 24 Feb 2010 02:11:11 -0500 Received: from toro.web-alm.net ([62.245.132.31]:44973 "EHLO toro.web-alm.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755097Ab0BXHLJ (ORCPT ); Wed, 24 Feb 2010 02:11:09 -0500 Message-ID: <4B84CFCB.4010001@osadl.org> Date: Wed, 24 Feb 2010 08:05:47 +0100 From: Carsten Emde Organization: Open Source Automation Development Lab (OSADL) eG User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) Gecko/20100120 Fedora/3.0.1-1.fc11 Thunderbird/3.0.1 MIME-Version: 1.0 To: Dan Carpenter , Thomas Gleixner , LKML , rt-users , Ingo Molnar , Steven Rostedt , Peter Zijlstra , Clark Williams , Frank Rowand , Robin Gareus , Gregory Haskins , Philippe Reynes , Fernando Lopez-Lezcano , Will Schmidt , Darren Hart , Jan Blunck , Sven-Thorsten Dietrich , Jon Masters , Mark Knecht , John Kacur , Nick Piggin Subject: Re: [patch] latency_hist: fix small memory leak References: <20100222132743.GB5416@bicker> In-Reply-To: <20100222132743.GB5416@bicker> X-Enigmail-Version: 1.0.1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2037 Lines: 68 On 02/22/2010 02:27 PM, Dan Carpenter wrote: > index_ptr needs to be freed on the error path. > > Signed-off-by: Dan Carpenter > > diff --git a/kernel/trace/latency_hist.c b/kernel/trace/latency_hist.c > index b3b5ea2..8edc70c 100644 > --- a/kernel/trace/latency_hist.c > +++ b/kernel/trace/latency_hist.c > @@ -204,8 +204,10 @@ static void *l_start(struct seq_file *m, loff_t *pos) > , my_hist->beyond_hist_bound_samples > , MAX_ENTRY_NUM, "samples"); > } > - if (index >= MAX_ENTRY_NUM) > + if (index >= MAX_ENTRY_NUM) { > + kfree(index_ptr); > return NULL; > + } > > *index_ptr = index; > return index_ptr; Thanks a lot for spotting this leak. We even don't need to allocate the memory, if index >= MAX_ENTRY_NUM. This patch applies to 2.6.31.12-rt21 and 2.6.33-rc8-rt (rt/head). Signed-off-by: Carsten Emde Index: head/kernel/trace/latency_hist.c =================================================================== --- head.orig/kernel/trace/latency_hist.c +++ head/kernel/trace/latency_hist.c @@ -218,13 +218,10 @@ void notrace latency_hist(int latency_ty static void *l_start(struct seq_file *m, loff_t *pos) { - loff_t *index_ptr = kmalloc(sizeof(loff_t), GFP_KERNEL); + loff_t *index_ptr = NULL; loff_t index = *pos; struct hist_data *my_hist = m->private; - if (!index_ptr) - return NULL; - if (index == 0) { char minstr[32], avgstr[32], maxstr[32]; @@ -263,10 +260,12 @@ static void *l_start(struct seq_file *m, MAX_ENTRY_NUM - my_hist->offset, "samples"); } - if (index >= MAX_ENTRY_NUM) - return NULL; + if (index < MAX_ENTRY_NUM) { + index_ptr = kmalloc(sizeof(loff_t), GFP_KERNEL); + if (index_ptr) + *index_ptr = index; + } - *index_ptr = index; return index_ptr; } -- 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/