Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH] selftests/alsa: Fix memory leak in find_controls error path
@ 2026-07-04 10:57 Malaya Kumar Rout
  2026-07-05  7:39 ` Takashi Iwai
  0 siblings, 1 reply; 2+ messages in thread
From: Malaya Kumar Rout @ 2026-07-04 10:57 UTC (permalink / raw)
  To: linux-kernel
  Cc: mrout, skhan, me, Malaya Kumar Rout, Mark Brown, Jaroslav Kysela,
	Takashi Iwai, Shuah Khan, linux-sound, linux-kselftest

In find_controls(), card_data is allocated with malloc() but when
snd_ctl_open_lconf() fails, the code jumps to next_card without
freeing the allocated memory. This results in a memory leak for
each card where snd_ctl_open_lconf() fails.

Add free(card_data) before goto next_card to ensure proper cleanup
of the allocated memory in the error path.

Fixes: 5aaf9efffc57 ("kselftest: alsa: Add simplistic test for ALSA mixer controls kselftest")
Signed-off-by: Malaya Kumar Rout <malayarout91@gmail.com>
---
 tools/testing/selftests/alsa/mixer-test.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/testing/selftests/alsa/mixer-test.c b/tools/testing/selftests/alsa/mixer-test.c
index d4f845c32804..c5ae2a026ce9 100644
--- a/tools/testing/selftests/alsa/mixer-test.c
+++ b/tools/testing/selftests/alsa/mixer-test.c
@@ -84,6 +84,7 @@ static void find_controls(void)
 		if (err < 0) {
 			ksft_print_msg("Failed to get hctl for card %d: %s\n",
 				       card, snd_strerror(err));
+			free(card_data);
 			goto next_card;
 		}
 
-- 
2.54.0


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

end of thread, other threads:[~2026-07-05  7:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-04 10:57 [PATCH] selftests/alsa: Fix memory leak in find_controls error path Malaya Kumar Rout
2026-07-05  7:39 ` Takashi Iwai

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