[PATCH] mem leak in tty_io.c

From: Brian Gerst
Date: Sat Oct 23 2004 - 22:01:35 EST


The recent patch to clean up user accesses introduced a memory leak. If write_buf is reallocated, the old buffer isn't freed. Also, since kfree can take nulls, I removed the if from the other kfree.

--
Brian Gerst
diff -urN linux-2.6.9-bk/drivers/char/tty_io.c linux/drivers/char/tty_io.c
--- linux-2.6.9-bk/drivers/char/tty_io.c 2004-10-22 09:53:21.373263820 -0400
+++ linux/drivers/char/tty_io.c 2004-10-22 10:36:10.753679871 -0400
@@ -168,8 +168,7 @@

static inline void free_tty_struct(struct tty_struct *tty)
{
- if (tty->write_buf)
- kfree(tty->write_buf);
+ kfree(tty->write_buf);
kfree(tty);
}

@@ -1060,6 +1059,7 @@
up(&tty->atomic_write);
return -ENOMEM;
}
+ kfree(tty->write_buf);
tty->write_cnt = chunk;
tty->write_buf = buf;
}