Skip to contentSkip to conversation

mem leak in tty_io.c

PATCH New Brian Gerst 1 participant 1 message Oct 24, 2004 Char and misc drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mem leak in tty_io.c

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

drivers/char/tty_io.c +2 -2
diff -urN linux-2.6.9-bk/drivers/char/tty_io.c linux/drivers/char/tty_io.c
@@ -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;
 	}