alsa-plugin: clean up the error handling

Also catch property copy errors.
This commit is contained in:
Wim Taymans 2026-05-05 16:25:56 +02:00
parent 6eac1efb20
commit ea25c3f2b1
2 changed files with 33 additions and 25 deletions

View file

@ -1248,6 +1248,7 @@ SND_CTL_PLUGIN_DEFINE_FUNC(pipewire)
int err; int err;
const char *str; const char *str;
snd_ctl_pipewire_t *ctl; snd_ctl_pipewire_t *ctl;
struct pw_properties *props2;
struct pw_loop *loop; struct pw_loop *loop;
pw_init(NULL, NULL); pw_init(NULL, NULL);
@ -1392,20 +1393,20 @@ SND_CTL_PLUGIN_DEFINE_FUNC(pipewire)
goto error; goto error;
pw_thread_loop_lock(ctl->mainloop); pw_thread_loop_lock(ctl->mainloop);
ctl->core = pw_context_connect(ctl->context, pw_properties_copy(ctl->props), 0); if ((props2 = pw_properties_copy(ctl->props)) == NULL)
if (ctl->core == NULL) { goto error_unlock_errno;
err = -errno;
goto error_unlock; ctl->core = pw_context_connect(ctl->context, props2, 0);
} if (ctl->core == NULL)
goto error_unlock_errno;
pw_core_add_listener(ctl->core, pw_core_add_listener(ctl->core,
&ctl->core_listener, &ctl->core_listener,
&core_events, ctl); &core_events, ctl);
ctl->registry = pw_core_get_registry(ctl->core, PW_VERSION_REGISTRY, 0); ctl->registry = pw_core_get_registry(ctl->core, PW_VERSION_REGISTRY, 0);
if (ctl->registry == NULL) { if (ctl->registry == NULL)
err = -errno; goto error_unlock_errno;
goto error_unlock;
}
pw_registry_add_listener(ctl->registry, pw_registry_add_listener(ctl->registry,
&ctl->registry_listener, &ctl->registry_listener,
@ -1437,6 +1438,8 @@ SND_CTL_PLUGIN_DEFINE_FUNC(pipewire)
return 0; return 0;
error_unlock_errno:
err = -errno;
error_unlock: error_unlock:
pw_thread_loop_unlock(ctl->mainloop); pw_thread_loop_unlock(ctl->mainloop);
error: error:

View file

@ -1269,6 +1269,7 @@ static int snd_pcm_pipewire_open(snd_pcm_t **pcmp,
struct pw_properties *props, snd_pcm_stream_t stream, int mode) struct pw_properties *props, snd_pcm_stream_t stream, int mode)
{ {
snd_pcm_pipewire_t *pw; snd_pcm_pipewire_t *pw;
struct pw_properties *props2;
int err; int err;
const char *str, *node_name = NULL; const char *str, *node_name = NULL;
struct pw_loop *loop; struct pw_loop *loop;
@ -1284,8 +1285,7 @@ static int snd_pcm_pipewire_open(snd_pcm_t **pcmp,
pw->log_file = fopencookie(pw, "w", io_funcs); pw->log_file = fopencookie(pw, "w", io_funcs);
if (pw->log_file == NULL) { if (pw->log_file == NULL) {
pw_log_error("can't create log file: %m"); pw_log_error("can't create log file: %m");
err = -errno; goto error_errno;
goto error;
} }
if ((err = snd_output_stdio_attach(&pw->output, pw->log_file, 0)) < 0) { if ((err = snd_output_stdio_attach(&pw->output, pw->log_file, 0)) < 0) {
pw_log_error("can't attach log file: %s", snd_strerror(err)); pw_log_error("can't attach log file: %s", snd_strerror(err));
@ -1293,20 +1293,17 @@ static int snd_pcm_pipewire_open(snd_pcm_t **pcmp,
} }
pw->main_loop = pw_thread_loop_new("alsa-pipewire", NULL); pw->main_loop = pw_thread_loop_new("alsa-pipewire", NULL);
if (pw->main_loop == NULL) { if (pw->main_loop == NULL)
err = -errno; goto error_errno;
goto error;
}
loop = pw_thread_loop_get_loop(pw->main_loop); loop = pw_thread_loop_get_loop(pw->main_loop);
pw->system = loop->system; pw->system = loop->system;
if ((pw->context = pw_context_new(loop, if ((pw->context = pw_context_new(loop,
pw_properties_new( pw_properties_new(
PW_KEY_CLIENT_API, "alsa", PW_KEY_CLIENT_API, "alsa",
NULL), NULL),
0)) == NULL) { 0)) == NULL)
err = -errno; goto error_errno;
goto error;
}
pw_context_conf_update_props(pw->context, "alsa.properties", pw->props); pw_context_conf_update_props(pw->context, "alsa.properties", pw->props);
@ -1356,12 +1353,14 @@ static int snd_pcm_pipewire_open(snd_pcm_t **pcmp,
goto error; goto error;
pw_thread_loop_lock(pw->main_loop); pw_thread_loop_lock(pw->main_loop);
pw->core = pw_context_connect(pw->context, pw_properties_copy(pw->props), 0); props2 = pw_properties_copy(pw->props);
if (pw->core == NULL) { if (props2 == NULL)
err = -errno; goto error_unlock_errno;
pw_thread_loop_unlock(pw->main_loop);
goto error; pw->core = pw_context_connect(pw->context, props2, 0);
} if (pw->core == NULL)
goto error_unlock_errno;
pw_core_add_listener(pw->core, &pw->core_listener, &core_events, pw); pw_core_add_listener(pw->core, &pw->core_listener, &core_events, pw);
pw_thread_loop_unlock(pw->main_loop); pw_thread_loop_unlock(pw->main_loop);
@ -1399,6 +1398,12 @@ static int snd_pcm_pipewire_open(snd_pcm_t **pcmp,
return 0; return 0;
error_unlock_errno:
err = -errno;
pw_thread_loop_unlock(pw->main_loop);
goto error;
error_errno:
err = -errno;
error: error:
pw_log_debug("%p: failed to open %s :%s", pw, node_name, spa_strerror(err)); pw_log_debug("%p: failed to open %s :%s", pw, node_name, spa_strerror(err));
snd_pcm_pipewire_free(pw); snd_pcm_pipewire_free(pw);