From: Stephen Hemminger <shemminger@osdl.org>
To: David Miller <davem@davemloft.net>
Cc: jesper.juhl@gmail.com, jmorris@namei.org, kuznet@ms2.inr.ac.ru,
yoshfuji@linux-ipv6.org, pekkas@netcore.fi, kaber@coreworks.de,
netdev@vger.kernel.org
Subject: Re: [PATCH] fix memory leak in net/ipv4/tcp_probe.c::tcpprobe_read()
Date: Thu, 10 Aug 2006 16:52:16 -0700 [thread overview]
Message-ID: <20060810165216.103c6940@localhost.localdomain> (raw)
In-Reply-To: <20060810.163612.71164812.davem@davemloft.net>
Dave, here is my version...
Don't leak memory on interrupted read. And only allocate
as much memory as needed.
Signed-off-by: Stephen Hemminger <shemminger@osdl.org>
--- linux-2.6.orig/net/ipv4/tcp_probe.c 2006-08-10 16:32:36.000000000 -0700
+++ linux-2.6/net/ipv4/tcp_probe.c 2006-08-10 16:45:30.000000000 -0700
@@ -114,7 +114,7 @@
static ssize_t tcpprobe_read(struct file *file, char __user *buf,
size_t len, loff_t *ppos)
{
- int error = 0, cnt = 0;
+ int error, cnt;
unsigned char *tbuf;
if (!buf || len < 0)
@@ -123,15 +123,16 @@
if (len == 0)
return 0;
- tbuf = vmalloc(len);
- if (!tbuf)
- return -ENOMEM;
-
error = wait_event_interruptible(tcpw.wait,
__kfifo_len(tcpw.fifo) != 0);
if (error)
return error;
+ len = min(len, kfifo_len(tcpw.fifo));
+ tbuf = vmalloc(len);
+ if (!tbuf)
+ return -ENOMEM;
+
cnt = kfifo_get(tcpw.fifo, tbuf, len);
error = copy_to_user(buf, tbuf, cnt);
next prev parent reply other threads:[~2006-08-10 23:53 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-07-30 19:38 [PATCH] fix memory leak in net/ipv4/tcp_probe.c::tcpprobe_read() Jesper Juhl
2006-07-30 21:29 ` Stephen Hemminger
2006-07-30 21:48 ` James Morris
2006-07-30 21:51 ` Jesper Juhl
2006-07-30 22:56 ` David Miller
2006-08-04 23:30 ` Jesper Juhl
2006-08-04 23:59 ` David Miller
2006-08-10 22:18 ` Jesper Juhl
2006-08-10 23:36 ` David Miller
2006-08-10 23:52 ` Stephen Hemminger [this message]
2006-08-10 23:54 ` David Miller
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=20060810165216.103c6940@localhost.localdomain \
--to=shemminger@osdl.org \
--cc=davem@davemloft.net \
--cc=jesper.juhl@gmail.com \
--cc=jmorris@namei.org \
--cc=kaber@coreworks.de \
--cc=kuznet@ms2.inr.ac.ru \
--cc=netdev@vger.kernel.org \
--cc=pekkas@netcore.fi \
--cc=yoshfuji@linux-ipv6.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;
as well as URLs for NNTP newsgroup(s).