improve error handling some more

This commit is contained in:
Wim Taymans 2019-06-20 11:04:34 +02:00
parent d1241e2c1c
commit a212d2f9ed
30 changed files with 393 additions and 312 deletions

View file

@ -57,6 +57,9 @@ struct device_data {
static void module_destroy(void *_data)
{
struct device_data *data = _data;
spa_hook_remove(&data->module_listener);
pw_device_destroy(data->this);
}
@ -69,23 +72,26 @@ SPA_EXPORT
int pipewire__module_init(struct pw_module *module, const char *args)
{
struct pw_properties *props = NULL;
char **argv;
char **argv = NULL;
int n_tokens;
struct pw_core *core = pw_module_get_core(module);
struct pw_device *device;
struct device_data *data;
int res;
if (args == NULL)
goto wrong_arguments;
goto error_arguments;
argv = pw_split_strv(args, " \t", 3, &n_tokens);
if (n_tokens < 2)
goto not_enough_arguments;
goto error_arguments;
if (n_tokens == 3) {
props = pw_properties_new_string(argv[2]);
if (props == NULL)
return -ENOMEM;
if (props == NULL) {
res = -errno;
goto error_exit_cleanup;
}
}
device = pw_spa_device_load(core,
@ -95,12 +101,13 @@ int pipewire__module_init(struct pw_module *module, const char *args)
0,
props,
sizeof(struct device_data));
if (device == NULL) {
res = -errno;
goto error_exit_cleanup;
}
pw_free_strv(argv);
if (device == NULL)
return -ENOMEM;
data = pw_spa_device_get_user_data(device);
data->this = device;
data->core = core;
@ -112,9 +119,12 @@ int pipewire__module_init(struct pw_module *module, const char *args)
return 0;
not_enough_arguments:
pw_free_strv(argv);
wrong_arguments:
error_arguments:
res = -EINVAL;
pw_log_error("usage: module-spa-device " MODULE_USAGE);
return -EINVAL;
goto error_exit_cleanup;
error_exit_cleanup:
if (argv)
pw_free_strv(argv);
return res;
}