netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Anton Moryakov <ant.v.moryakov@gmail.com>
To: netdev@vger.kernel.org
Cc: Anton Moryakov <ant.v.moryakov@gmail.com>
Subject: [PATCH iproute2-next] misc: fix memory leak in ifstat.c
Date: Sat, 19 Jul 2025 13:18:52 +0300	[thread overview]
Message-ID: <20250719101852.31514-1-ant.v.moryakov@gmail.com> (raw)

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>
---
 misc/ifstat.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/misc/ifstat.c b/misc/ifstat.c
index 4ce5ca8a..5b59fd8f 100644
--- a/misc/ifstat.c
+++ b/misc/ifstat.c
@@ -139,6 +139,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);
+			free(n->name);
 			return 0;
 		}
 		memcpy(&n->val, RTA_DATA(attr), sizeof(n->val));
-- 
2.39.2


             reply	other threads:[~2025-07-19 10:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-19 10:18 Anton Moryakov [this message]
2025-07-20 15:12 ` [PATCH iproute2-next] misc: fix memory leak in ifstat.c Stephen Hemminger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250719101852.31514-1-ant.v.moryakov@gmail.com \
    --to=ant.v.moryakov@gmail.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).