]> git.alsa-project.org Git - alsa-lib.git/commitdiff
pcm: chmap: Fix memory leak at snd_pcm_set_chmap()
authorTakashi Iwai <tiwai@suse.de>
Tue, 24 Sep 2019 11:48:37 +0000 (13:48 +0200)
committerTakashi Iwai <tiwai@suse.de>
Tue, 24 Sep 2019 11:48:37 +0000 (13:48 +0200)
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

index 178d43875f004e97549a201868bb9928bb185f54..d6bf31ac7ae38d606b876af432bce76fc48379cc 100644 (file)
@@ -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)