Skip to contentSkip to conversation

pcm: chmap: Fix memory leak at snd_pcm_set_chmap()

PATCH New Takashi Iwai 1 participant 1 message Sep 24, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pcm: chmap: Fix memory leak at snd_pcm_set_chmap()

snd_pcm_set_chmap() leaks the memory returned from snd_pcm_get_chmap() without releasing. Add the missing free() call as well as a slight code refactoring.

Reported-by Conrad Jones
Fixes d20e24e5d161 ("chmap: Always succeed setting the map to what it already is")
---
 src/pcm/pcm.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
src/pcm/pcm.c +7 -2
index 178d43875f00..d6bf31ac7ae3 100644
@@ -8099,8 +8099,13 @@ snd_pcm_chmap_t *snd_pcm_get_chmap(snd_pcm_t *pcm)
  */
 int snd_pcm_set_chmap(snd_pcm_t *pcm, const snd_pcm_chmap_t *map)
 {
-	const snd_pcm_chmap_t *oldmap = snd_pcm_get_chmap(pcm);
-	if (oldmap && chmap_equal(oldmap, map))
+	const snd_pcm_chmap_t *oldmap;
+	int nochange;
+
+	oldmap = snd_pcm_get_chmap(pcm);
+	nochange = (oldmap && chmap_equal(oldmap, map));
+	free((void *)oldmap);
+	if (nochange)
 		return 0;
 
 	if (!pcm->ops->set_chmap)
Signature · 6 lines
2.16.4

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel