netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Patch net] cls_cgroup: fix memory leak in cls_cgroup_change()
@ 2014-01-03 19:13 Cong Wang
  2014-01-04  2:02 ` David Miller
  0 siblings, 1 reply; 4+ messages in thread
From: Cong Wang @ 2014-01-03 19:13 UTC (permalink / raw)
  To: netdev; +Cc: Cong Wang, Thomas Graf, David S. Miller, Jamal Hadi Salim

Fix it by moving allocation to ->init().

Cc: Thomas Graf <tgraf@suug.ch>
Cc: David S. Miller <davem@davemloft.net>
Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
---
 net/sched/cls_cgroup.c | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/net/sched/cls_cgroup.c b/net/sched/cls_cgroup.c
index 16006c9..f0d1e81 100644
--- a/net/sched/cls_cgroup.c
+++ b/net/sched/cls_cgroup.c
@@ -169,6 +169,11 @@ static void cls_cgroup_put(struct tcf_proto *tp, unsigned long f)
 
 static int cls_cgroup_init(struct tcf_proto *tp)
 {
+	struct cls_cgroup_head *head;
+	head = kzalloc(sizeof(*head), GFP_KERNEL);
+	if (head == NULL)
+		return -ENOBUFS;
+	tp->root = head;
 	return 0;
 }
 
@@ -195,21 +200,9 @@ static int cls_cgroup_change(struct net *net, struct sk_buff *in_skb,
 	if (!tca[TCA_OPTIONS])
 		return -EINVAL;
 
-	if (head == NULL) {
-		if (!handle)
-			return -EINVAL;
-
-		head = kzalloc(sizeof(*head), GFP_KERNEL);
-		if (head == NULL)
-			return -ENOBUFS;
-
+	if (head->handle == 0)
 		head->handle = handle;
 
-		tcf_tree_lock(tp);
-		tp->root = head;
-		tcf_tree_unlock(tp);
-	}
-
 	if (handle != head->handle)
 		return -ENOENT;
 
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-01-07 21:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-03 19:13 [Patch net] cls_cgroup: fix memory leak in cls_cgroup_change() Cong Wang
2014-01-04  2:02 ` David Miller
2014-01-06 23:23   ` Cong Wang
2014-01-07 21:19     ` Thomas Graf

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).