| From d28b33f44b57ec171be735fd12511e6059672376 Mon Sep 17 00:00:00 2001 |
| From: Carsten Emde <C.Emde@osadl.org> |
| Date: Wed, 24 Feb 2010 07:49:32 +0100 |
| Subject: [PATCH] tracing: Plug memory leak in histogram_show |
| |
| commit d28b33f44b57ec171be735fd12511e6059672376 in tip. |
| |
| Do not allocate memory for index pointer, if index out of range. |
| |
| Reported-by: Dan Carpenter <error27@gmail.com> |
| Signed-off-by: Carsten Emde <C.Emde@osadl.org> |
| Signed-off-by: Thomas Gleixner <tglx@linutronix.de> |
| |
| diff --git a/kernel/trace/latency_hist.c b/kernel/trace/latency_hist.c |
| index 8300929..9f20d61 100644 |
| --- a/kernel/trace/latency_hist.c |
| +++ b/kernel/trace/latency_hist.c |
| @@ -218,13 +218,10 @@ void notrace latency_hist(int latency_type, int cpu, unsigned long latency, |
| |
| 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, loff_t *pos) |
| 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; |
| } |
| |
| -- |
| 1.7.1.1 |
| |