spa: alsa: avoid potential uninitialized variable use

In both funtions `ctl_hndl` could be passed to `snd_ctl_close()`
while being unitialized if `this->device_info.change_mask` is zero.
This commit is contained in:
Barnabás Pőcze 2024-06-28 01:50:55 +02:00 committed by Wim Taymans
parent 27b76ae686
commit ab2907c699
2 changed files with 22 additions and 16 deletions

View file

@ -242,8 +242,6 @@ static int emit_info(struct impl *this, bool full)
int err = 0;
struct spa_dict_item items[20];
uint32_t n_items = 0;
snd_ctl_t *ctl_hndl;
snd_ctl_card_info_t *info;
char path[128];
char device_name[200];
char device_desc[200];
@ -252,6 +250,9 @@ static int emit_info(struct impl *this, bool full)
this->device_info.change_mask = this->info_all;
if (this->device_info.change_mask) {
snd_ctl_card_info_t *info;
snd_ctl_t *ctl_hndl;
spa_log_debug(this->log, "open card %s", this->props.device);
if ((err = snd_ctl_open(&ctl_hndl, this->props.device, 0)) < 0) {
spa_log_error(this->log, "can't open control for card %s: %s",
@ -260,9 +261,14 @@ static int emit_info(struct impl *this, bool full)
}
snd_ctl_card_info_alloca(&info);
if ((err = snd_ctl_card_info(ctl_hndl, info)) < 0) {
err = snd_ctl_card_info(ctl_hndl, info);
spa_log_debug(this->log, "close card %s", this->props.device);
snd_ctl_close(ctl_hndl);
if (err < 0) {
spa_log_error(this->log, "error hardware info: %s", snd_strerror(err));
goto finish;
return err;
}
snprintf(path, sizeof(path), "alsa:compressed:%s", snd_ctl_card_info_get_id(info));
@ -297,10 +303,7 @@ static int emit_info(struct impl *this, bool full)
this->device_info.change_mask = 0;
}
finish:
spa_log_debug(this->log, "close card %s", this->props.device);
snd_ctl_close(ctl_hndl);
return err;
return 0;
}
static int impl_add_listener(void *object,

View file

@ -247,14 +247,15 @@ static int emit_info(struct impl *this, bool full)
int err = 0;
struct spa_dict_item items[20];
uint32_t n_items = 0;
snd_ctl_t *ctl_hndl;
snd_ctl_card_info_t *info;
char path[128];
if (full)
this->device_info.change_mask = this->info_all;
if (this->device_info.change_mask) {
snd_ctl_card_info_t *info;
snd_ctl_t *ctl_hndl;
spa_log_debug(this->log, "open card %s", this->props.device);
if ((err = snd_ctl_open(&ctl_hndl, this->props.device, 0)) < 0) {
spa_log_error(this->log, "can't open control for card %s: %s",
@ -263,9 +264,14 @@ static int emit_info(struct impl *this, bool full)
}
snd_ctl_card_info_alloca(&info);
if ((err = snd_ctl_card_info(ctl_hndl, info)) < 0) {
err = snd_ctl_card_info(ctl_hndl, info);
spa_log_debug(this->log, "close card %s", this->props.device);
snd_ctl_close(ctl_hndl);
if (err < 0) {
spa_log_error(this->log, "error hardware info: %s", snd_strerror(err));
goto exit;
return err;
}
#define ADD_ITEM(key, value) items[n_items++] = SPA_DICT_ITEM_INIT(key, value)
@ -296,10 +302,7 @@ static int emit_info(struct impl *this, bool full)
this->device_info.change_mask = 0;
}
exit:
spa_log_debug(this->log, "close card %s", this->props.device);
snd_ctl_close(ctl_hndl);
return err;
return 0;
}
static int impl_add_listener(void *object,