diff mbox series

[alsa-lib] pcm: chmap: Fix memory leak at snd_pcm_set_chmap()

Message ID 20190924115228.24008-1-tiwai@suse.de (mailing list archive)
State New, archived
Headers show
Series [alsa-lib] pcm: chmap: Fix memory leak at snd_pcm_set_chmap() | expand

Commit Message

Takashi Iwai Sept. 24, 2019, 11:52 a.m. UTC
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@suse.de>
---
 src/pcm/pcm.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
diff mbox series

Patch

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)