]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
devlink: fix memory leak in ifname_map_rtnl_init()
authorMinhong He <heminhong@kylinos.cn>
Mon, 25 Nov 2024 03:24:54 +0000 (11:24 +0800)
committerStephen Hemminger <stephen@networkplumber.org>
Thu, 28 Nov 2024 03:58:54 +0000 (19:58 -0800)
When the return value of rtnl_talk() is greater than
or equal to 0, 'answer' will be allocated.
The 'answer' should be free after using,
otherwise it will cause memory leak.

Signed-off-by: Minhong He <heminhong@kylinos.cn>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
devlink/devlink.c

index 9907712e3ad0839365be1ec607a79e5fc8abc51f..abe96f345db7ca97fba460cfb92151e6bce148d3 100644 (file)
@@ -846,7 +846,7 @@ static int ifname_map_rtnl_init(struct dl *dl, const char *ifname)
        struct rtattr *tb[IFLA_MAX + 1];
        struct rtnl_handle rth;
        struct ifinfomsg *ifi;
-       struct nlmsghdr *n;
+       struct nlmsghdr *n = NULL;
        int len;
        int err;
 
@@ -887,6 +887,7 @@ static int ifname_map_rtnl_init(struct dl *dl, const char *ifname)
        err = ifname_map_rtnl_port_parse(dl, ifname, tb[IFLA_DEVLINK_PORT]);
 
 out:
+       free(n);
        rtnl_close(&rth);
        return err;
 }