netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH iproute] ip: fix memory leak in 'ip maddr show'
@ 2023-10-15 14:32 Maxim Petrov
  2023-10-16 16:20 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Maxim Petrov @ 2023-10-15 14:32 UTC (permalink / raw)
  To: netdev; +Cc: Stephen Hemminger

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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-10-16 16:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-15 14:32 [PATCH iproute] ip: fix memory leak in 'ip maddr show' Maxim Petrov
2023-10-16 16:20 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).