From: David Härdeman Date: Sat, 10 Feb 2024 00:44:48 +0000 (+0100) Subject: netlink: fix a memory leak X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=066b3dc6ec1a679ce5cd2353d90f8f735193ff40;p=project%2Fodhcpd.git netlink: fix a memory leak 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 --- 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)