Skip to contentSkip to conversation

ip: fix memory leak in 'ip maddr show'

PATCH Applied Maxim Petrov 2 participants 2 messages Oct 15, 2023 – Oct 16, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ip: fix memory leak in 'ip maddr show'

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"

---
 ip/ipmaddr.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
ip/ipmaddr.c +11 -0
index 176f6ab7..2418b303 100644
@@ -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;
 }
 
Signature · 1 line
2.30.2
#1 lore raw
This patch was applied to iproute2/iproute2.git (main) by Stephen Hemminger <[email protected]>:

Hello:

This patch was applied to iproute2/iproute2.git (main) by Stephen Hemminger <[email protected]>:

Quoted 8 lines · On Sun, 15 Oct 2023 16:32:12 +0200 you wrote:

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"

[...]

Here is the summary with links:
- [iproute] ip: fix memory leak in 'ip maddr show'

    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=575322b09c3c

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html