From: Maxim Petrov <mmrmaximuzz@gmail.com>
To: netdev@vger.kernel.org
Cc: Stephen Hemminger <stephen@networkplumber.org>
Subject: [PATCH iproute] ip: fix memory leak in 'ip maddr show'
Date: Sun, 15 Oct 2023 16:32:12 +0200 [thread overview]
Message-ID: <7be84294-b02e-4280-89fb-cf222fbf0239@gmail.com> (raw)
In `read_dev_mcast`, the list of ma_info is allocated, but not cleared
after use. Free the list in the end to make valgrind happy.
Detected by valgrind: "valgrind ./ip/ip maddr show"
Signed-off-by: Maxim Petrov <mmrmaximuzz@gmail.com>
---
ip/ipmaddr.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/ip/ipmaddr.c b/ip/ipmaddr.c
index 176f6ab7..2418b303 100644
--- a/ip/ipmaddr.c
+++ b/ip/ipmaddr.c
@@ -79,6 +79,16 @@ static void maddr_ins(struct ma_info **lst, struct ma_info *m)
*lst = m;
}
+static void maddr_clear(struct ma_info *lst)
+{
+ struct ma_info *mp;
+
+ while ((mp = lst) != NULL) {
+ lst = mp->next;
+ free(mp);
+ }
+}
+
static void read_dev_mcast(struct ma_info **result_p)
{
char buf[256];
@@ -286,6 +296,7 @@ static int multiaddr_list(int argc, char **argv)
if (!filter.family || filter.family == AF_INET6)
read_igmp6(&list);
print_mlist(stdout, list);
+ maddr_clear(list);
return 0;
}
--
2.30.2
next reply other threads:[~2023-10-15 14:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-15 14:32 Maxim Petrov [this message]
2023-10-16 16:20 ` [PATCH iproute] ip: fix memory leak in 'ip maddr show' patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7be84294-b02e-4280-89fb-cf222fbf0239@gmail.com \
--to=mmrmaximuzz@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.