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:
Pauli Virtanen 2021-05-17 18:19:44 +03:00
parent cb6dbd165a
commit 2b515b5e50
6 changed files with 58 additions and 9 deletions

View file

@ -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)