From: channing <chao.bi@intel.com>
To: gregkh@linuxfoundation.org, jslaby@suse.cz
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] TTY: memory leakage in tty_buffer_find()
Date: Wed, 26 Jun 2013 16:51:10 +0800 [thread overview]
Message-ID: <1372236670.2390.12.camel@bichao> (raw)
In tty_buffer_find(), it scans all tty buffers in
free buffer queue, if it finds matched one,
tty->buf.free will point to matched one's next buffer,
so tty buffers that ahead of matched one are removed
from free queue, they will never be used but they
are not released, then memory leak happen.
This patch is to make tty_buffer_find() only extract
the matched tty buffer, and keep others left inside
free queue, so that they could be found and used next
time.
Signed-off-by: Chao Bi <chao.bi@intel.com>
---
drivers/tty/tty_buffer.c | 7 ++++++-
1 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/drivers/tty/tty_buffer.c b/drivers/tty/tty_buffer.c
index 9121c1f..7b10f7a 100644
--- a/drivers/tty/tty_buffer.c
+++ b/drivers/tty/tty_buffer.c
@@ -178,10 +178,14 @@ void tty_buffer_flush(struct tty_struct *tty)
static struct tty_buffer *tty_buffer_find(struct tty_port *port, size_t size)
{
struct tty_buffer **tbh = &port->buf.free;
+ struct tty_buffer *prev = NULL;
while ((*tbh) != NULL) {
struct tty_buffer *t = *tbh;
if (t->size >= size) {
- *tbh = t->next;
+ if (prev == NULL)
+ *tbh = t->next;
+ else
+ prev->next = t->next;
t->next = NULL;
t->used = 0;
t->commit = 0;
@@ -189,6 +193,7 @@ static struct tty_buffer *tty_buffer_find(struct tty_port *port, size_t size)
port->buf.memory_used += t->size;
return t;
}
+ prev = t;
tbh = &((*tbh)->next);
}
/* Round the buffer size out */
--
1.7.1
next reply other threads:[~2013-06-26 8:32 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-26 8:51 channing [this message]
2013-06-26 8:55 ` [PATCH] TTY: memory leakage in tty_buffer_find() Jiri Slaby
2013-06-26 9:01 ` Jiri Slaby
2013-06-26 12:43 ` Peter Hurley
2013-06-27 2:37 ` channing
2013-06-27 12:44 ` Peter Hurley
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=1372236670.2390.12.camel@bichao \
--to=chao.bi@intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=jslaby@suse.cz \
--cc=linux-kernel@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