[alsa-devel] [PATCH alsa-lib] pcm: chmap: Fix memory leak at snd_pcm_set_chmap()
Takashi Iwai
tiwai at suse.de
Tue Sep 24 13:52:28 CEST 2019
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
BugLink: https://github.com/alsa-project/alsa-lib/pull/11
Fixes: d20e24e5d161 ("chmap: Always succeed setting the map to what it already is")
Signed-off-by: Takashi Iwai <tiwai at suse.de>
---
src/pcm/pcm.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c
index 178d43875f00..d6bf31ac7ae3 100644
--- a/src/pcm/pcm.c
+++ b/src/pcm/pcm.c
@@ -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)
--
2.16.4
More information about the Alsa-devel
mailing list