mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-11-01 22:58:49 -04:00
pcm_hw: fix possible memory leak (coverity)
This commit is contained in:
parent
822e781a47
commit
0f4f48d377
2 changed files with 21 additions and 17 deletions
|
|
@ -7512,7 +7512,7 @@ snd_pcm_chmap_query_t **snd_pcm_query_chmaps(snd_pcm_t *pcm)
|
||||||
*/
|
*/
|
||||||
void snd_pcm_free_chmaps(snd_pcm_chmap_query_t **maps)
|
void snd_pcm_free_chmaps(snd_pcm_chmap_query_t **maps)
|
||||||
{
|
{
|
||||||
snd_pcm_chmap_query_t **p = maps;
|
snd_pcm_chmap_query_t **p;
|
||||||
if (!maps)
|
if (!maps)
|
||||||
return;
|
return;
|
||||||
for (p = maps; *p; p++)
|
for (p = maps; *p; p++)
|
||||||
|
|
|
||||||
|
|
@ -1693,12 +1693,14 @@ int _snd_pcm_hw_open(snd_pcm_t **pcmp, const char *name,
|
||||||
err = snd_config_get_string(n, &str);
|
err = snd_config_get_string(n, &str);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
SNDERR("Invalid type for %s", id);
|
SNDERR("Invalid type for %s", id);
|
||||||
return -EINVAL;
|
err = -EINVAL;
|
||||||
|
goto fail;
|
||||||
}
|
}
|
||||||
card = snd_card_get_index(str);
|
card = snd_card_get_index(str);
|
||||||
if (card < 0) {
|
if (card < 0) {
|
||||||
SNDERR("Invalid value for %s", id);
|
SNDERR("Invalid value for %s", id);
|
||||||
return card;
|
err = card;
|
||||||
|
goto fail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -1707,7 +1709,7 @@ int _snd_pcm_hw_open(snd_pcm_t **pcmp, const char *name,
|
||||||
err = snd_config_get_integer(n, &device);
|
err = snd_config_get_integer(n, &device);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
SNDERR("Invalid type for %s", id);
|
SNDERR("Invalid type for %s", id);
|
||||||
return err;
|
goto fail;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -1715,7 +1717,7 @@ int _snd_pcm_hw_open(snd_pcm_t **pcmp, const char *name,
|
||||||
err = snd_config_get_integer(n, &subdevice);
|
err = snd_config_get_integer(n, &subdevice);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
SNDERR("Invalid type for %s", id);
|
SNDERR("Invalid type for %s", id);
|
||||||
return err;
|
goto fail;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -1738,7 +1740,7 @@ int _snd_pcm_hw_open(snd_pcm_t **pcmp, const char *name,
|
||||||
err = snd_config_get_integer(n, &val);
|
err = snd_config_get_integer(n, &val);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
SNDERR("Invalid type for %s", id);
|
SNDERR("Invalid type for %s", id);
|
||||||
return err;
|
goto fail;
|
||||||
}
|
}
|
||||||
rate = val;
|
rate = val;
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -1747,7 +1749,7 @@ int _snd_pcm_hw_open(snd_pcm_t **pcmp, const char *name,
|
||||||
err = snd_config_get_string(n, &str);
|
err = snd_config_get_string(n, &str);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
SNDERR("invalid type for %s", id);
|
SNDERR("invalid type for %s", id);
|
||||||
return err;
|
goto fail;
|
||||||
}
|
}
|
||||||
format = snd_pcm_format_value(str);
|
format = snd_pcm_format_value(str);
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -1757,7 +1759,7 @@ int _snd_pcm_hw_open(snd_pcm_t **pcmp, const char *name,
|
||||||
err = snd_config_get_integer(n, &val);
|
err = snd_config_get_integer(n, &val);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
SNDERR("Invalid type for %s", id);
|
SNDERR("Invalid type for %s", id);
|
||||||
return err;
|
goto fail;
|
||||||
}
|
}
|
||||||
channels = val;
|
channels = val;
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -1767,26 +1769,24 @@ int _snd_pcm_hw_open(snd_pcm_t **pcmp, const char *name,
|
||||||
chmap = _snd_pcm_parse_config_chmaps(n);
|
chmap = _snd_pcm_parse_config_chmaps(n);
|
||||||
if (!chmap) {
|
if (!chmap) {
|
||||||
SNDERR("Invalid channel map for %s", id);
|
SNDERR("Invalid channel map for %s", id);
|
||||||
return -EINVAL;
|
goto fail;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
SNDERR("Unknown field %s", id);
|
SNDERR("Unknown field %s", id);
|
||||||
snd_pcm_free_chmaps(chmap);
|
err = -EINVAL;
|
||||||
return -EINVAL;
|
goto fail;
|
||||||
}
|
}
|
||||||
if (card < 0) {
|
if (card < 0) {
|
||||||
SNDERR("card is not defined");
|
SNDERR("card is not defined");
|
||||||
snd_pcm_free_chmaps(chmap);
|
err = -EINVAL;
|
||||||
return -EINVAL;
|
goto fail;
|
||||||
}
|
}
|
||||||
err = snd_pcm_hw_open(pcmp, name, card, device, subdevice, stream,
|
err = snd_pcm_hw_open(pcmp, name, card, device, subdevice, stream,
|
||||||
mode | (nonblock ? SND_PCM_NONBLOCK : 0),
|
mode | (nonblock ? SND_PCM_NONBLOCK : 0),
|
||||||
0, sync_ptr_ioctl);
|
0, sync_ptr_ioctl);
|
||||||
if (err < 0) {
|
if (err < 0)
|
||||||
snd_pcm_free_chmaps(chmap);
|
goto fail;
|
||||||
return err;
|
|
||||||
}
|
|
||||||
if (nonblock && ! (mode & SND_PCM_NONBLOCK)) {
|
if (nonblock && ! (mode & SND_PCM_NONBLOCK)) {
|
||||||
/* revert to blocking mode for read/write access */
|
/* revert to blocking mode for read/write access */
|
||||||
snd_pcm_hw_nonblock(*pcmp, 0);
|
snd_pcm_hw_nonblock(*pcmp, 0);
|
||||||
|
|
@ -1810,6 +1810,10 @@ int _snd_pcm_hw_open(snd_pcm_t **pcmp, const char *name,
|
||||||
hw->chmap_override = chmap;
|
hw->chmap_override = chmap;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
snd_pcm_free_chmaps(chmap);
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef DOC_HIDDEN
|
#ifndef DOC_HIDDEN
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue