]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
misc: fix memory leak in ifstat.c
authorAnton Moryakov <ant.v.moryakov@gmail.com>
Sat, 19 Jul 2025 10:42:12 +0000 (13:42 +0300)
committerDavid Ahern <dsahern@kernel.org>
Tue, 29 Jul 2025 23:12:34 +0000 (23:12 +0000)
A memory leak was detected by the static analyzer SVACE in the function
get_nlmsg_extended(). The issue occurred when parsing extended interface
statistics failed due to a missing nested attribute. In this case,
memory allocated for 'n->name' via strdup() was not freed before returning,
resulting in a leak.

The fix adds an explicit 'free(n->name)' call before freeing the containing
structure in the error path.

Reported-by: SVACE static analyzer
Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
misc/ifstat.c

index faebe938e59891497710910e1b96d41419978967..a47d0b169f2381af24d5818df1a2575e04098f67 100644 (file)
@@ -152,6 +152,7 @@ static int get_nlmsg_extended(struct nlmsghdr *m, void *arg)
 
                attr = parse_rtattr_one_nested(sub_type, tb[filter_type]);
                if (attr == NULL) {
+                       free(n->name);
                        free(n);
                        return 0;
                }