pulse-server: also release and free the dbus name

This commit is contained in:
Wim Taymans 2021-03-26 15:14:53 +01:00
parent 109411bd2b
commit 4112b34f4d
2 changed files with 26 additions and 10 deletions

View file

@ -25,7 +25,7 @@
#include <dbus/dbus.h>
#include <spa/support/dbus.h>
static int dbus_request_name(struct pw_context *context, const char *name)
static void *dbus_request_name(struct pw_context *context, const char *name)
{
struct spa_dbus *dbus;
struct spa_dbus_connection *conn;
@ -37,12 +37,14 @@ static int dbus_request_name(struct pw_context *context, const char *name)
support = pw_context_get_support(context, &n_support);
dbus = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_DBus);
if (dbus == NULL)
return -ENOTSUP;
if (dbus == NULL) {
errno = ENOTSUP;
return NULL;
}
conn = spa_dbus_get_connection(dbus, SPA_DBUS_TYPE_SESSION);
if (conn == NULL)
return -errno;
return NULL;
bus = spa_dbus_connection_get(conn);
@ -51,7 +53,7 @@ static int dbus_request_name(struct pw_context *context, const char *name)
if (dbus_bus_request_name(bus, name,
DBUS_NAME_FLAG_DO_NOT_QUEUE,
&error) == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
return 0;
return conn;
if (dbus_error_is_set(&error))
pw_log_error("Failed to acquire %s: %s: %s", name, error.name, error.message);
@ -60,5 +62,12 @@ static int dbus_request_name(struct pw_context *context, const char *name)
dbus_error_free(&error);
return -EEXIST;
errno = EEXIST;
return NULL;
}
static void dbus_release_name(void *data)
{
struct spa_dbus_connection *conn = data;
spa_dbus_connection_destroy(conn);
}

View file

@ -265,6 +265,7 @@ struct impl {
struct spa_hook context_listener;
struct pw_properties *props;
void *dbus_name;
struct ratelimit rate_limit;
@ -6272,6 +6273,13 @@ static void impl_free(struct impl *impl)
{
struct server *s;
struct client *c;
struct message *msg;
if (impl->dbus_name)
dbus_release_name(impl->dbus_name);
spa_list_consume(msg, &impl->free_messages, link)
message_free(impl, msg, true, true);
if (impl->context != NULL)
spa_hook_remove(&impl->context_listener);
@ -6279,10 +6287,12 @@ static void impl_free(struct impl *impl)
client_free(c);
spa_list_consume(s, &impl->servers, link)
server_free(s);
pw_map_for_each(&impl->samples, impl_free_sample, impl);
pw_map_clear(&impl->samples);
pw_map_for_each(&impl->modules, impl_free_module, impl);
pw_map_clear(&impl->modules);
if (impl->cleanup != NULL)
pw_loop_destroy_source(impl->loop, impl->cleanup);
pw_properties_free(impl->props);
@ -6399,7 +6409,7 @@ struct pw_protocol_pulse *pw_protocol_pulse_new(struct pw_context *context,
}
}
dbus_request_name(context, "org.pulseaudio.Server");
impl->dbus_name = dbus_request_name(context, "org.pulseaudio.Server");
return (struct pw_protocol_pulse*)impl;
@ -6419,8 +6429,5 @@ void *pw_protocol_pulse_get_user_data(struct pw_protocol_pulse *pulse)
void pw_protocol_pulse_destroy(struct pw_protocol_pulse *pulse)
{
struct impl *impl = (struct impl*)pulse;
struct message *msg;
spa_list_consume(msg, &impl->free_messages, link)
message_free(impl, msg, true, true);
impl_free(impl);
}