aplay: fix memory leak when setup_chmap() fail

setup_chmap() will return with error number if hw_map calloc fail or
channels doesn't match with hw_params, but memory free was ignored when
error occurs.

Signed-off-by: chunxu.li <chunxuxiao@gmail.com>
Reviewed-by: Takashi Sakamoto o-takashi@sakamocchi.jp
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
chunxu.li 2019-06-23 23:54:29 +08:00 committed by Jaroslav Kysela
parent 192fb6220a
commit d40e724905

View file

@ -1262,6 +1262,7 @@ static int setup_chmap(void)
hw_map = calloc(hwparams.channels, sizeof(int)); hw_map = calloc(hwparams.channels, sizeof(int));
if (!hw_map) { if (!hw_map) {
error(_("not enough memory")); error(_("not enough memory"));
free(hw_chmap);
return -1; return -1;
} }
@ -1284,6 +1285,7 @@ static int setup_chmap(void)
error(_("Channel %d doesn't match with hw_parmas"), ch); error(_("Channel %d doesn't match with hw_parmas"), ch);
snd_pcm_chmap_print(hw_chmap, sizeof(buf), buf); snd_pcm_chmap_print(hw_chmap, sizeof(buf), buf);
fprintf(stderr, "hardware chmap = %s\n", buf); fprintf(stderr, "hardware chmap = %s\n", buf);
free(hw_chmap);
return -1; return -1;
} }
} }