Skip to contentSkip to conversation

misc: fix memory leak in ifstat.c

PATCH Applied Anton Moryakov 2 participants 2 messages Jul 19, 2025 – Jul 29, 2025

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

PATCH v2 1/1 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
---
 misc/ifstat.c | 1 +
 1 file changed, 1 insertion(+)
misc/ifstat.c +1 -0
index 4ce5ca8a..3de20c63 100644
@@ -138,6 +138,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;
 		}
Signature · 1 line
2.39.2
#1 lore raw
This patch was applied to iproute2/iproute2-next.git (main) by David Ahern <[email protected]>:

Hello:

This patch was applied to iproute2/iproute2-next.git (main) by David Ahern <[email protected]>:

Quoted 10 lines · On Sat, 19 Jul 2025 13:42:12 +0300 you wrote:

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.

[...]

Here is the summary with links:
- [V2,iproute2-next] misc: fix memory leak in ifstat.c

    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=0b09a1b053a2

You are awesome, thank you!

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