[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20241125032454.35392-1-heminhong@kylinos.cn>
Date: Mon, 25 Nov 2024 11:24:54 +0800
From: Minhong He <heminhong@...inos.cn>
To: stephen@...workplumber.org,
netdev@...r.kernel.org
Cc: Minhong He <heminhong@...inos.cn>
Subject: [PATCH] devlink: fix memory leak in ifname_map_rtnl_init()
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@...inos.cn>
---
devlink/devlink.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/devlink/devlink.c b/devlink/devlink.c
index 9907712e..abe96f34 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -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;
}
--
2.25.1
Powered by blists - more mailing lists