From 066b3dc6ec1a679ce5cd2353d90f8f735193ff40 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20H=C3=A4rdeman?= Date: Sat, 10 Feb 2024 01:44:48 +0100 Subject: [PATCH] netlink: fix a memory leak MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit valgrind noted that addrs is allocated in netlink_get_interface_linklocal(), but never freed in one case. While I was looking at that, I found a mysterious double-realloc in netlink.c. Signed-off-by: David Härdeman --- src/config.c | 5 ++--- src/netlink.c | 6 ------ 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/config.c b/src/config.c index 42fc2fe..78dd0a2 100644 --- a/src/config.c +++ b/src/config.c @@ -938,13 +938,12 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr addrs_len = netlink_get_interface_linklocal(iface->ifindex, &addrs); if (addrs_len > 0) { for (ssize_t i = 0; i < addrs_len; i++) { - struct odhcpd_ipaddr *addr = &addrs[i]; - - if (!addr->tentative) { + if (!addrs[i].tentative) { iface->have_link_local = true; break; } } + free(addrs); } iface->inuse = true; diff --git a/src/netlink.c b/src/netlink.c index 368e69c..6b38caa 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -807,12 +807,6 @@ static int cb_linklocal_valid(struct nl_msg *msg, void *arg) return NL_SKIP; memset(&addrs[ctxt->ret], 0, sizeof(addrs[ctxt->ret])); - - addrs = realloc(addrs, sizeof(*addrs)*(ctxt->ret + 1)); - if (!addrs) - return NL_SKIP; - - memcpy(&addrs[ctxt->ret].addr, &addr, sizeof(addrs[ctxt->ret].addr)); if (ifa->ifa_flags & IFA_F_TENTATIVE) -- 2.30.2