浏览代码

genetlink: fix a memory leak on error path

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>
Signed-off-by: David S. Miller <davem@davemloft.net>
WANG Cong 8 年之前
父节点
当前提交
00ffc1ba02
共有 1 个文件被更改,包括 3 次插入1 次删除
  1. 3 1
      net/netlink/genetlink.c

+ 3 - 1
net/netlink/genetlink.c

@@ -404,7 +404,7 @@ int __genl_register_family(struct genl_family *family)
 
 
 	err = genl_validate_assign_mc_groups(family);
 	err = genl_validate_assign_mc_groups(family);
 	if (err)
 	if (err)
-		goto errout_locked;
+		goto errout_free;
 
 
 	list_add_tail(&family->family_list, genl_family_chain(family->id));
 	list_add_tail(&family->family_list, genl_family_chain(family->id));
 	genl_unlock_all();
 	genl_unlock_all();
@@ -417,6 +417,8 @@ int __genl_register_family(struct genl_family *family)
 
 
 	return 0;
 	return 0;
 
 
+errout_free:
+	kfree(family->attrbuf);
 errout_locked:
 errout_locked:
 	genl_unlock_all();
 	genl_unlock_all();
 errout:
 errout: