LKML Archive on lore.kernel.org
 help / color / Atom feed
From: Zhouyi Zhou <yizhouzhou@ict.ac.cn>
To: akpm@linux-foundation.org, penberg@kernel.org,
	viro@zeniv.linux.org.uk, linux-kernel@vger.kernel.org
Cc: Zhouyi Zhou <yizhouzhou@ict.ac.cn>, Zhouyi Zhou <zhouzhouyi@gmail.com>
Subject: [PATCH] relay: fix potential memory leak
Date: Wed,  1 Jun 2016 18:45:27 +0800
Message-ID: <1464777927-19675-1-git-send-email-yizhouzhou@ict.ac.cn> (raw)

when relay_open_buf fails in relay_open, program will goto free_bufs,
but chan is nowhere freed.

In addition, give warning to users who forget to provide create file
hook. 	 

Signed-off-by: Zhouyi Zhou <zhouzhouyi@gmail.com>
---
 kernel/relay.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/kernel/relay.c b/kernel/relay.c
index 074994b..e0990c7 100644
--- a/kernel/relay.c
+++ b/kernel/relay.c
@@ -589,6 +589,13 @@ struct rchan *relay_open(const char *base_filename,
 	chan->parent = parent;
 	chan->private_data = private_data;
 	if (base_filename) {
+		if (!cb || !cb->create_buf_file) {
+			printk(KERN_ERR
+			       "relay_open: has base filename without "
+			       "providing hook to create file\n");
+			kfree(chan);
+			return NULL;
+		}
 		chan->has_base_filename = 1;
 		strlcpy(chan->base_filename, base_filename, NAME_MAX);
 	}
@@ -614,6 +621,7 @@ free_bufs:
 
 	kref_put(&chan->kref, relay_destroy_channel);
 	mutex_unlock(&relay_channels_mutex);
+	kfree(chan);
 	return NULL;
 }
 EXPORT_SYMBOL_GPL(relay_open);
-- 
1.9.1

             reply index

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-01 10:45 Zhouyi Zhou [this message]
2016-06-01 21:56 ` Andrew Morton
2016-06-02  1:24   ` Zhouyi Zhou
2016-06-02  2:11     ` Andrew Morton

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=1464777927-19675-1-git-send-email-yizhouzhou@ict.ac.cn \
    --to=yizhouzhou@ict.ac.cn \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=penberg@kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=zhouzhouyi@gmail.com \
    /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

LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lore.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lore.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lore.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lore.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lore.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lore.kernel.org/lkml/6 lkml/git/6.git
	git clone --mirror https://lore.kernel.org/lkml/7 lkml/git/7.git
	git clone --mirror https://lore.kernel.org/lkml/8 lkml/git/8.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ https://lore.kernel.org/lkml \
		linux-kernel@vger.kernel.org
	public-inbox-index lkml

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git