netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Patch net] genetlink: fix a memory leak on error path
@ 2016-11-03 16:42 Cong Wang
  2016-11-03 16:42 ` [Patch net] taskstats: fix the length of cgroupstats_cmd_get_policy Cong Wang
  2016-11-03 20:53 ` [Patch net] genetlink: fix a memory leak on error path David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Cong Wang @ 2016-11-03 16:42 UTC (permalink / raw)
  To: netdev; +Cc: Cong Wang, Jakub Kicinski, Johannes Berg

In __genl_register_family(), when genl_validate_assign_mc_groups()
fails, we forget to free the memory we possibly allocate for
family->attrbuf.

Note, some callers call genl_unregister_family() to clean up
on error path, it doesn't work because the family is inserted
to the global list in the nearly last step.

Cc: Jakub Kicinski <kubakici@wp.pl>
Cc: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
---
 net/netlink/genetlink.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c
index 23cc126..49c28e8 100644
--- a/net/netlink/genetlink.c
+++ b/net/netlink/genetlink.c
@@ -404,7 +404,7 @@ int __genl_register_family(struct genl_family *family)
 
 	err = genl_validate_assign_mc_groups(family);
 	if (err)
-		goto errout_locked;
+		goto errout_free;
 
 	list_add_tail(&family->family_list, genl_family_chain(family->id));
 	genl_unlock_all();
@@ -417,6 +417,8 @@ int __genl_register_family(struct genl_family *family)
 
 	return 0;
 
+errout_free:
+	kfree(family->attrbuf);
 errout_locked:
 	genl_unlock_all();
 errout:
-- 
2.1.0

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

end of thread, other threads:[~2016-11-03 20:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-03 16:42 [Patch net] genetlink: fix a memory leak on error path Cong Wang
2016-11-03 16:42 ` [Patch net] taskstats: fix the length of cgroupstats_cmd_get_policy Cong Wang
2016-11-03 20:53 ` [Patch net] genetlink: fix a memory leak on error path David Miller

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