mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-12-20 08:56:56 -05:00
dbus: keep a ref to DBusConnection if reconnecting is not handled
Several places in the code don't handle reconnecting DBus connections yet. In those cases, a ref to the DBusConnection handle needs to be kept, so that there's no use-after-free if it gets freed by spa_dbus if the connection is broken. Adjust spa_dbus so that others keeping additional refs is safe.
This commit is contained in:
parent
cb6dbd165a
commit
2b515b5e50
6 changed files with 58 additions and 9 deletions
|
|
@ -192,6 +192,9 @@ int main(int argc, char *argv[])
|
|||
goto exit;
|
||||
}
|
||||
|
||||
/* XXX: we don't handle dbus reconnection yet, so ref the handle instead */
|
||||
dbus_connection_ref(impl.conn);
|
||||
|
||||
impl.device = rd_device_new(impl.conn,
|
||||
opt_name,
|
||||
opt_appname,
|
||||
|
|
@ -207,6 +210,10 @@ int main(int argc, char *argv[])
|
|||
rd_device_release(impl.device);
|
||||
|
||||
exit:
|
||||
if (impl.conn)
|
||||
dbus_connection_unref(impl.conn);
|
||||
if (impl.dbus)
|
||||
spa_dbus_connection_destroy(impl.dbus_connection);
|
||||
if (impl.context)
|
||||
pw_context_destroy(impl.context);
|
||||
if (impl.mainloop)
|
||||
|
|
|
|||
|
|
@ -111,6 +111,8 @@ static void module_destroy(void *data)
|
|||
spa_hook_remove(&impl->context_listener);
|
||||
spa_hook_remove(&impl->module_listener);
|
||||
|
||||
if (impl->bus)
|
||||
dbus_connection_unref(impl->bus);
|
||||
spa_dbus_connection_destroy(impl->conn);
|
||||
|
||||
pw_properties_free(impl->properties);
|
||||
|
|
@ -240,6 +242,9 @@ static int init_dbus_connection(struct impl *impl)
|
|||
if (impl->bus == NULL)
|
||||
return -EIO;
|
||||
|
||||
/* XXX: we don't handle dbus reconnection yet, so ref the handle instead */
|
||||
dbus_connection_ref(impl->bus);
|
||||
|
||||
dbus_error_init(&error);
|
||||
|
||||
dbus_bus_add_match(impl->bus,
|
||||
|
|
|
|||
|
|
@ -55,8 +55,10 @@ void *dbus_request_name(struct pw_context *context, const char *name)
|
|||
return NULL;
|
||||
|
||||
bus = spa_dbus_connection_get(conn);
|
||||
if (bus == NULL)
|
||||
if (bus == NULL) {
|
||||
spa_dbus_connection_destroy(conn);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dbus_error_init(&error);
|
||||
|
||||
|
|
@ -72,6 +74,8 @@ void *dbus_request_name(struct pw_context *context, const char *name)
|
|||
|
||||
dbus_error_free(&error);
|
||||
|
||||
spa_dbus_connection_destroy(conn);
|
||||
|
||||
errno = EEXIST;
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue