Skip to content

Commit

Permalink
link: link_msg_parser(): keep link info instead of release and reacquire
Browse files Browse the repository at this point in the history
Calling release_link_info() will call io_free() for rtnl_link::l_info
was allocated just a few lines before as a side effect of
rtnl_link_set_type().

Apart from doing needless memory churn, this will also leave the link
with l_info set to NULL if the link type does not provide a io_parse()
function.

Assuming the memory leak mentioned in bfee88b ("route: fix memory
leak of l_info_ops in link_msg_parser()") was a double reference taken
by calling rtnl_link_info_ops_lookup() twice, once via
rtnl_link_set_type(), and once directly, replace the lookup() /
release() lookup() with a single lookup() and then reuse the populated
rtnl_link::l_info_ops pointer.

Fixes: bfee88b ("route: fix memory leak of l_info_ops in link_msg_parser()")
Signed-off-by: Jonas Gorski <[email protected]>
  • Loading branch information
KanjiMonster committed Aug 5, 2024
1 parent fa05d58 commit 0e774d4
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions lib/route/link.c
Original file line number Diff line number Diff line change
Expand Up @@ -681,11 +681,7 @@ static int link_msg_parser(struct nl_cache_ops *ops, struct sockaddr_nl *who,
tb[IFLA_PROTINFO] = (struct nlattr *)link->l_af_ops->ao_protinfo_policy;
}

if (link->l_info_ops)
release_link_info(link);

ops = rtnl_link_info_ops_lookup(kind);
link->l_info_ops = ops;
ops = link->l_info_ops;

if (ops) {
if (ops->io_parse &&
Expand Down

0 comments on commit 0e774d4

Please sign in to comment.