lkml.org 
[lkml]   [2005]   [Aug]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [PATCH] sg.c: fix a memory leak in devices seq_file implementation (2nd)
Ingo Oeser schrieb:
>
> kfree() checks its argument, so instead of
>
> if (pointer)
> kfree(pointer);
>
> just do
>
> kfree(pointer);
>

This is an updated patch. Removed the unnecessary if.

Signed-off-by: Jan Blunck <j.blunck@tu-harburg.de>

drivers/scsi/sg.c | 15 ++++++++-------
1 files changed, 8 insertions(+), 7 deletions(-)

Index: linux-2.6/drivers/scsi/sg.c
===================================================================
--- linux-2.6.orig/drivers/scsi/sg.c
+++ linux-2.6/drivers/scsi/sg.c
@@ -2971,23 +2971,22 @@ static void * dev_seq_start(struct seq_f
{
struct sg_proc_deviter * it = kmalloc(sizeof(*it), GFP_KERNEL);

+ s->private = it;
if (! it)
return NULL;
+
if (NULL == sg_dev_arr)
- goto err1;
+ return NULL;
it->index = *pos;
it->max = sg_last_dev();
if (it->index >= it->max)
- goto err1;
+ return NULL;
return it;
-err1:
- kfree(it);
- return NULL;
}

static void * dev_seq_next(struct seq_file *s, void *v, loff_t *pos)
{
- struct sg_proc_deviter * it = (struct sg_proc_deviter *) v;
+ struct sg_proc_deviter * it = s->private;

*pos = ++it->index;
return (it->index < it->max) ? it : NULL;
@@ -2995,7 +2994,9 @@ static void * dev_seq_next(struct seq_fi

static void dev_seq_stop(struct seq_file *s, void *v)
{
- kfree (v);
+ struct sg_proc_deviter * it = s->private;
+
+ kfree (it);
}

static int sg_proc_open_dev(struct inode *inode, struct file *file)
\
 
 \ /
  Last update: 2005-08-23 22:28    [W:0.046 / U:0.152 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site