]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
ip: fix memory leak in 'ip maddr show'
authorMaxim Petrov <mmrmaximuzz@gmail.com>
Sun, 15 Oct 2023 14:32:12 +0000 (16:32 +0200)
committerStephen Hemminger <stephen@networkplumber.org>
Mon, 16 Oct 2023 16:15:04 +0000 (09:15 -0700)
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

index 176f6ab74b9440c294f3ef881cc94b287bf94dca..2418b303130e3a83e980f2d1c555326f357db769 100644 (file)
@@ -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;
 }