From: Jeff Liu <jeff.liu@oracle.com>
To: linux-serial@vger.kernel.org
Subject: [PATCH] drivers/tty/tty_io.c: fix a potential memleak at do_tty_write()
Date: Mon, 18 Jun 2012 20:23:54 +0800 [thread overview]
Message-ID: <4FDF1DDA.3030704@oracle.com> (raw)
Hello,
Looks there is a potential memory leak at drivers/tty/tty_io.c: do_tty_write().
It did allocate a buf_chunk if tty->write_cnt < chunk, however, buf_chunk was not
freed after the writing is done. Below tiny patch could fix it.
Thanks,
-Jeff
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index b425c79..f09e73e 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -1011,6 +1011,7 @@ static inline ssize_t do_tty_write(
size_t count)
{
ssize_t ret, written = 0;
+ unsigned char *buf_chunk = NULL;
unsigned int chunk;
ret = tty_write_lock(tty, file->f_flags & O_NDELAY);
@@ -1041,8 +1042,6 @@ static inline ssize_t do_tty_write(
/* write_buf/write_cnt is protected by the atomic_write_lock mutex */
if (tty->write_cnt < chunk) {
- unsigned char *buf_chunk;
-
if (chunk < 1024)
chunk = 1024;
@@ -1082,6 +1081,9 @@ static inline ssize_t do_tty_write(
inode->i_mtime = current_fs_time(inode->i_sb);
ret = written;
}
+
+ if (buf_chunk)
+ kfree(buf_chunk);
out:
tty_write_unlock(tty);
return ret;
next reply other threads:[~2012-06-18 12:24 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-18 12:23 Jeff Liu [this message]
2012-06-18 15:26 ` [PATCH] drivers/tty/tty_io.c: fix a potential memleak at do_tty_write() Greg KH
2012-06-18 16:04 ` Alan Cox
2012-06-18 18:00 ` Paul Fulghum
2012-06-19 3:44 ` Jeff Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4FDF1DDA.3030704@oracle.com \
--to=jeff.liu@oracle.com \
--cc=linux-serial@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox