mirror of
https://gitlab.freedesktop.org/pipewire/pipewire
synced 2024-10-14 20:02:38 +00:00
protocol-native: clean up security context on unload
This commit is contained in:
parent
df50952f48
commit
c2ba66bef6
|
@ -175,7 +175,8 @@ static const struct spa_dict_item module_props[] = {
|
|||
|
||||
void pw_protocol_native_init(struct pw_protocol *protocol);
|
||||
void pw_protocol_native0_init(struct pw_protocol *protocol);
|
||||
int protocol_native_security_context_init(struct pw_impl_module *module, struct pw_protocol *protocol);
|
||||
void *protocol_native_security_context_init(struct pw_impl_module *module, struct pw_protocol *protocol);
|
||||
void protocol_native_security_context_free(void *data);
|
||||
|
||||
struct protocol_data {
|
||||
struct pw_impl_module *module;
|
||||
|
@ -183,6 +184,7 @@ struct protocol_data {
|
|||
struct pw_protocol *protocol;
|
||||
|
||||
struct pw_properties *props;
|
||||
void *security;
|
||||
|
||||
struct server *local;
|
||||
};
|
||||
|
@ -1620,6 +1622,7 @@ static void module_destroy(void *data)
|
|||
{
|
||||
struct protocol_data *d = data;
|
||||
|
||||
protocol_native_security_context_free(d->security);
|
||||
spa_hook_remove(&d->module_listener);
|
||||
pw_properties_free(d->props);
|
||||
|
||||
|
@ -1816,7 +1819,7 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args_str)
|
|||
goto error_cleanup;
|
||||
}
|
||||
|
||||
protocol_native_security_context_init(module, this);
|
||||
d->security = protocol_native_security_context_init(module, this);
|
||||
|
||||
props = pw_context_get_properties(context);
|
||||
pw_properties_update_keys(d->props, &props->dict, keys);
|
||||
|
|
|
@ -15,6 +15,7 @@ PW_LOG_TOPIC_EXTERN(mod_topic_connection);
|
|||
struct impl {
|
||||
struct pw_context *context;
|
||||
struct pw_global *global;
|
||||
struct spa_hook listener;
|
||||
|
||||
struct pw_protocol *protocol;
|
||||
};
|
||||
|
@ -114,7 +115,30 @@ global_bind(void *object, struct pw_impl_client *client, uint32_t permissions,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int protocol_native_security_context_init(struct pw_impl_module *module, struct pw_protocol *protocol)
|
||||
|
||||
static void global_free(void *data)
|
||||
{
|
||||
struct impl *impl = data;
|
||||
if (impl->global) {
|
||||
spa_hook_remove(&impl->listener);
|
||||
impl->global = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static const struct pw_global_events global_events = {
|
||||
PW_VERSION_GLOBAL_EVENTS,
|
||||
.free = global_free
|
||||
};
|
||||
|
||||
void protocol_native_security_context_free(void *data)
|
||||
{
|
||||
struct impl *impl = data;
|
||||
if (impl->global)
|
||||
pw_global_destroy(impl->global);
|
||||
free(impl);
|
||||
}
|
||||
|
||||
void *protocol_native_security_context_init(struct pw_impl_module *module, struct pw_protocol *protocol)
|
||||
{
|
||||
struct pw_context *context = pw_impl_module_get_context(module);
|
||||
struct impl *impl;
|
||||
|
@ -130,7 +154,7 @@ int protocol_native_security_context_init(struct pw_impl_module *module, struct
|
|||
|
||||
impl = calloc(1, sizeof(struct impl));
|
||||
if (impl == NULL)
|
||||
return -errno;
|
||||
return NULL;
|
||||
|
||||
impl->context = context;
|
||||
impl->protocol = protocol;
|
||||
|
@ -143,13 +167,15 @@ int protocol_native_security_context_init(struct pw_impl_module *module, struct
|
|||
global_bind, impl);
|
||||
if (impl->global == NULL) {
|
||||
free(impl);
|
||||
return -errno;
|
||||
return NULL;
|
||||
}
|
||||
spa_scnprintf(serial_str, sizeof(serial_str), "%"PRIu64,
|
||||
pw_global_get_serial(impl->global));
|
||||
pw_global_update_keys(impl->global, &extra_props, keys);
|
||||
|
||||
pw_global_add_listener(impl->global, &impl->listener, &global_events, impl);
|
||||
|
||||
pw_global_register(impl->global);
|
||||
|
||||
return 0;
|
||||
return impl;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue