Skip to content

Commit 59b3661

Browse files
congwangdavem330
authored andcommitted
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 <[email protected]> Cc: Jon Maloy <[email protected]> Cc: Ying Xue <[email protected]> Signed-off-by: Cong Wang <[email protected]> Acked-by: Ying Xue <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 749439b commit 59b3661

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

net/tipc/node.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1880,36 +1880,38 @@ int tipc_nl_node_get_link(struct sk_buff *skb, struct genl_info *info)
18801880

18811881
if (strcmp(name, tipc_bclink_name) == 0) {
18821882
err = tipc_nl_add_bc_link(net, &msg);
1883-
if (err) {
1884-
nlmsg_free(msg.skb);
1885-
return err;
1886-
}
1883+
if (err)
1884+
goto err_free;
18871885
} else {
18881886
int bearer_id;
18891887
struct tipc_node *node;
18901888
struct tipc_link *link;
18911889

18921890
node = tipc_node_find_by_name(net, name, &bearer_id);
1893-
if (!node)
1894-
return -EINVAL;
1891+
if (!node) {
1892+
err = -EINVAL;
1893+
goto err_free;
1894+
}
18951895

18961896
tipc_node_read_lock(node);
18971897
link = node->links[bearer_id].link;
18981898
if (!link) {
18991899
tipc_node_read_unlock(node);
1900-
nlmsg_free(msg.skb);
1901-
return -EINVAL;
1900+
err = -EINVAL;
1901+
goto err_free;
19021902
}
19031903

19041904
err = __tipc_nl_add_link(net, &msg, link, 0);
19051905
tipc_node_read_unlock(node);
1906-
if (err) {
1907-
nlmsg_free(msg.skb);
1908-
return err;
1909-
}
1906+
if (err)
1907+
goto err_free;
19101908
}
19111909

19121910
return genlmsg_reply(msg.skb, info);
1911+
1912+
err_free:
1913+
nlmsg_free(msg.skb);
1914+
return err;
19131915
}
19141916

19151917
int tipc_nl_node_reset_link_stats(struct sk_buff *skb, struct genl_info *info)

0 commit comments

Comments
 (0)