spa: audiotestsrc: Validate loop and system before using them

Makes sure we don't crash if those are not available (like with
DataSystem under spa-inspect).

Fixes: https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/4365
This commit is contained in:
Arun Raghavan 2024-10-23 08:24:25 -04:00
parent 2c132be626
commit f0b81a4628

View file

@ -1046,8 +1046,18 @@ impl_init(const struct spa_handle_factory *factory,
this = (struct impl *) handle;
this->log = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_Log);
this->data_loop = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_DataLoop);
if (this->data_loop == NULL) {
spa_log_error(this->log, "%p: could not find a data loop", this);
return -EINVAL;
}
this->data_system = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_DataSystem);
if (this->data_system == NULL) {
spa_log_error(this->log, "%p: could not find a data system", this);
return -EINVAL;
}
for (i = 0; info && i < info->n_items; i++) {
const char *k = info->items[i].key;