BPF List
 help / color / mirror / Atom feed
* [PATCH] selftests/bpf: Fix memory leak in msg_alloc_iov error path
@ 2026-07-04 11:10 Malaya Kumar Rout
  2026-07-04 11:47 ` bot+bpf-ci
  0 siblings, 1 reply; 5+ messages in thread
From: Malaya Kumar Rout @ 2026-07-04 11:10 UTC (permalink / raw)
  To: linux-kernel, bpf
  Cc: mrout, skhan, me, Malaya Kumar Rout, Andrii Nakryiko,
	Eduard Zingerman, Alexei Starovoitov, Daniel Borkmann,
	Kumar Kartikeya Dwivedi, Martin KaFai Lau, Song Liu,
	Yonghong Song, Jiri Olsa, Emil Tsalapatis, Shuah Khan,
	John Fastabend, linux-kselftest

In msg_alloc_iov(), when calloc() fails for an individual iov_base
allocation, the error path frees all previously allocated iov_base
entries but fails to free the iov array itself that was allocated
with calloc() at the beginning of the function. This results in a
memory leak of the iov array.

Add free(iov) in the unwind_iov error path to ensure proper cleanup
of all allocated memory.

Fixes: 16962b2404ac ("bpf: sockmap, add selftests")
Signed-off-by: Malaya Kumar Rout <malayarout91@gmail.com>
---
 tools/testing/selftests/bpf/test_sockmap.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/testing/selftests/bpf/test_sockmap.c b/tools/testing/selftests/bpf/test_sockmap.c
index ac814eb63edb..3e6be455d158 100644
--- a/tools/testing/selftests/bpf/test_sockmap.c
+++ b/tools/testing/selftests/bpf/test_sockmap.c
@@ -436,6 +436,7 @@ static int msg_alloc_iov(struct msghdr *msg,
 unwind_iov:
 	for (i--; i >= 0 ; i--)
 		free(msg->msg_iov[i].iov_base);
+	free(iov);
 	return -ENOMEM;
 }
 
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-07-06 19:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-04 11:10 [PATCH] selftests/bpf: Fix memory leak in msg_alloc_iov error path Malaya Kumar Rout
2026-07-04 11:47 ` bot+bpf-ci
2026-07-04 12:29   ` [PATCH v2] " Malaya Kumar Rout
2026-07-06 16:04     ` Emil Tsalapatis
2026-07-06 19:30     ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox