[PATCH] mixer: Fix memory leak for more than 16 file descriptor case

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: David Fries <David@xxxxxxxxx>
Reviewed-by: Takashi Iwai <tiwai@xxxxxxx>
---
Added signed off.

I saw this when digging through the source code, wrote up a test case,
and verified with valgrind. I don't have that many sound cards so I
modified mixer.c to always take the conditional. alloca seemed like
the least effort way to fix this. Other thoughts were to test pfds !=
spfds and free, but given how little bytes would be allocated putting
on the stack seems reasonable.

I also created the github pull request 20.
https://github.com/alsa-project/alsa-lib/pull/20

 src/mixer/mixer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/mixer/mixer.c b/src/mixer/mixer.c
index 82056474..b1af9945 100644
--- a/src/mixer/mixer.c
+++ b/src/mixer/mixer.c
@@ -767,7 +767,7 @@ int snd_mixer_wait(snd_mixer_t *mixer, int timeout)
 	if (count < 0)
 		return count;
 	if ((unsigned int) count > sizeof(spfds) / sizeof(spfds[0])) {
-		pfds = malloc(count * sizeof(*pfds));
+		pfds = alloca(count * sizeof(*pfds));
 		if (!pfds)
 			return -ENOMEM;
 		err = snd_mixer_poll_descriptors(mixer, pfds, 
-- 
2.11.0

_______________________________________________
Alsa-devel mailing list
Alsa-devel@xxxxxxxxxxxxxxxx
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel



[Index of Archives]     [ALSA User]     [Linux Audio Users]     [Pulse Audio]     [Kernel Archive]     [Asterisk PBX]     [Photo Sharing]     [Linux Sound]     [Video 4 Linux]     [Gimp]     [Yosemite News]

  Powered by Linux