diff options
author | Cong Wang <xiyou.wangcong@gmail.com> | 2018-01-10 15:50:25 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2018-01-15 13:45:50 -0500 |
commit | 59b36613e85fb16ebf9feaf914570879cd5c2a21 (patch) | |
tree | 9219f64c5110f0f7b4865420b154e649cca774e5 /net/tipc/node.c | |
parent | 749439bfac6e1a2932c582e2699f91d329658196 (diff) |
tipc: fix a memory leak in tipc_nl_node_get_link()
When tipc_node_find_by_name() fails, the nlmsg is not
freed.
While on it, switch to a goto label to properly
free it.
Fixes: be9c086715c ("tipc: narrow down exposure of struct tipc_node")
Reported-by: Dmitry Vyukov <dvyukov@google.com>
Cc: Jon Maloy <jon.maloy@ericsson.com>
Cc: Ying Xue <ying.xue@windriver.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Acked-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/tipc/node.c')
-rw-r--r-- | net/tipc/node.c | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/net/tipc/node.c b/net/tipc/node.c index 507017fe0f1b..9036d8756e73 100644 --- a/net/tipc/node.c +++ b/net/tipc/node.c | |||
@@ -1880,36 +1880,38 @@ int tipc_nl_node_get_link(struct sk_buff *skb, struct genl_info *info) | |||
1880 | 1880 | ||
1881 | if (strcmp(name, tipc_bclink_name) == 0) { | 1881 | if (strcmp(name, tipc_bclink_name) == 0) { |
1882 | err = tipc_nl_add_bc_link(net, &msg); | 1882 | err = tipc_nl_add_bc_link(net, &msg); |
1883 | if (err) { | 1883 | if (err) |
1884 | nlmsg_free(msg.skb); | 1884 | goto err_free; |
1885 | return err; | ||
1886 | } | ||
1887 | } else { | 1885 | } else { |
1888 | int bearer_id; | 1886 | int bearer_id; |
1889 | struct tipc_node *node; | 1887 | struct tipc_node *node; |
1890 | struct tipc_link *link; | 1888 | struct tipc_link *link; |
1891 | 1889 | ||
1892 | node = tipc_node_find_by_name(net, name, &bearer_id); | 1890 | node = tipc_node_find_by_name(net, name, &bearer_id); |
1893 | if (!node) | 1891 | if (!node) { |
1894 | return -EINVAL; | 1892 | err = -EINVAL; |
1893 | goto err_free; | ||
1894 | } | ||
1895 | 1895 | ||
1896 | tipc_node_read_lock(node); | 1896 | tipc_node_read_lock(node); |
1897 | link = node->links[bearer_id].link; | 1897 | link = node->links[bearer_id].link; |
1898 | if (!link) { | 1898 | if (!link) { |
1899 | tipc_node_read_unlock(node); | 1899 | tipc_node_read_unlock(node); |
1900 | nlmsg_free(msg.skb); | 1900 | err = -EINVAL; |
1901 | return -EINVAL; | 1901 | goto err_free; |
1902 | } | 1902 | } |
1903 | 1903 | ||
1904 | err = __tipc_nl_add_link(net, &msg, link, 0); | 1904 | err = __tipc_nl_add_link(net, &msg, link, 0); |
1905 | tipc_node_read_unlock(node); | 1905 | tipc_node_read_unlock(node); |
1906 | if (err) { | 1906 | if (err) |
1907 | nlmsg_free(msg.skb); | 1907 | goto err_free; |
1908 | return err; | ||
1909 | } | ||
1910 | } | 1908 | } |
1911 | 1909 | ||
1912 | return genlmsg_reply(msg.skb, info); | 1910 | return genlmsg_reply(msg.skb, info); |
1911 | |||
1912 | err_free: | ||
1913 | nlmsg_free(msg.skb); | ||
1914 | return err; | ||
1913 | } | 1915 | } |
1914 | 1916 | ||
1915 | int tipc_nl_node_reset_link_stats(struct sk_buff *skb, struct genl_info *info) | 1917 | int tipc_nl_node_reset_link_stats(struct sk_buff *skb, struct genl_info *info) |