mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-06 13:30:01 -05:00
pulse-server: module-switch-on-connect: remove dead code and one allocation
As Coverity correctly points out, the `if (blocklist)` condition is never true after the `out` label, so this commit makes some changes to remove the dead code. First of all, the `regex_t` object is directly embedded in the module's data struct, so the `malloc()` call can be removed, and thus there is no need for the cleanup code anymore, so everything after the `out` label is also removed. Furthermore, two NULL checks are removed which check `d->blocklist` from `module_switch_on_connect_unload()` and `manager_added()` because both of those functions can only ever run if the `d->blocklist` regex object has been successfully initialized in `module_switch_on_connect_prepare()`. Those checks were not strictly needed to begin with.
This commit is contained in:
parent
8949d45c69
commit
c248091528
1 changed files with 5 additions and 29 deletions
|
|
@ -52,7 +52,7 @@ struct module_switch_on_connect_data {
|
||||||
struct spa_hook manager_listener;
|
struct spa_hook manager_listener;
|
||||||
struct pw_manager_object *metadata_default;
|
struct pw_manager_object *metadata_default;
|
||||||
|
|
||||||
regex_t *blocklist;
|
regex_t blocklist;
|
||||||
|
|
||||||
int sync_seq;
|
int sync_seq;
|
||||||
|
|
||||||
|
|
@ -122,7 +122,7 @@ static void manager_added(void *data, struct pw_manager_object *o)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (d->blocklist && regexec(d->blocklist, name, 0, NULL, 0) == 0) {
|
if (regexec(&d->blocklist, name, 0, NULL, 0) == 0) {
|
||||||
pw_log_debug("not switching to blocklisted device");
|
pw_log_debug("not switching to blocklisted device");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -224,11 +224,7 @@ static int module_switch_on_connect_unload(struct module *module)
|
||||||
d->core = NULL;
|
d->core = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (d->blocklist) {
|
regfree(&d->blocklist);
|
||||||
regfree(d->blocklist);
|
|
||||||
free(d->blocklist);
|
|
||||||
d->blocklist = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -249,10 +245,8 @@ static int module_switch_on_connect_prepare(struct module * const module)
|
||||||
{
|
{
|
||||||
struct module_switch_on_connect_data * const d = module->user_data;
|
struct module_switch_on_connect_data * const d = module->user_data;
|
||||||
struct pw_properties * const props = module->props;
|
struct pw_properties * const props = module->props;
|
||||||
regex_t *blocklist = NULL;
|
|
||||||
bool only_from_unavailable = false, ignore_virtual = true;
|
bool only_from_unavailable = false, ignore_virtual = true;
|
||||||
const char *str;
|
const char *str;
|
||||||
int res;
|
|
||||||
|
|
||||||
PW_LOG_TOPIC_INIT(mod_topic);
|
PW_LOG_TOPIC_INIT(mod_topic);
|
||||||
|
|
||||||
|
|
@ -266,25 +260,15 @@ static int module_switch_on_connect_prepare(struct module * const module)
|
||||||
pw_properties_set(props, "ignore_virtual", NULL);
|
pw_properties_set(props, "ignore_virtual", NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((blocklist = malloc(sizeof(regex_t))) == NULL) {
|
|
||||||
res = -ENOMEM;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((str = pw_properties_get(props, "blocklist")) == NULL)
|
if ((str = pw_properties_get(props, "blocklist")) == NULL)
|
||||||
str = DEFAULT_BLOCKLIST;
|
str = DEFAULT_BLOCKLIST;
|
||||||
|
|
||||||
if ((res = regcomp(blocklist, str, REG_NOSUB | REG_EXTENDED)) != 0) {
|
if (regcomp(&d->blocklist, str, REG_NOSUB | REG_EXTENDED) != 0)
|
||||||
free(blocklist);
|
return -EINVAL;
|
||||||
blocklist = NULL;
|
|
||||||
res = -EINVAL;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
pw_properties_set(props, "blocklist", NULL);
|
pw_properties_set(props, "blocklist", NULL);
|
||||||
|
|
||||||
d->module = module;
|
d->module = module;
|
||||||
d->blocklist = blocklist;
|
|
||||||
d->ignore_virtual = ignore_virtual;
|
d->ignore_virtual = ignore_virtual;
|
||||||
d->only_from_unavailable = only_from_unavailable;
|
d->only_from_unavailable = only_from_unavailable;
|
||||||
|
|
||||||
|
|
@ -294,14 +278,6 @@ static int module_switch_on_connect_prepare(struct module * const module)
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
out:
|
|
||||||
if (blocklist) {
|
|
||||||
regfree(blocklist);
|
|
||||||
free(blocklist);
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DEFINE_MODULE_INFO(module_switch_on_connect) = {
|
DEFINE_MODULE_INFO(module_switch_on_connect) = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue