misc: fix memory leak in ifstat.c
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>
diff --git a/misc/ifstat.c b/misc/ifstat.c
index faebe93..a47d0b1 100644
--- a/misc/ifstat.c
+++ b/misc/ifstat.c
@@ -152,6 +152,7 @@
attr = parse_rtattr_one_nested(sub_type, tb[filter_type]);
if (attr == NULL) {
+ free(n->name);
free(n);
return 0;
}