Re: [patch] latency_hist: fix small memory leak

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <error27@xxxxxxxxx>
> 
> 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 <C.Emde@xxxxxxxxx>

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-rt-users" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [RT Stable]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux