[PATCH 2/4] dbus-client: assign service name before running callback

Christian Eggers <[email protected]> Wed, 25 Jun 2025 15:14:30 +0200
Newsgroups dev.linux.lists.ell
Message-ID <[email protected]>
If the service name we are looking for is already in the cache,
_dbus_name_cache_add_watch() will call the connect_func callback
immediately (before client->service has been assigned). This breaks
service_appeared_callback(), where the service name is required for
making the initial GetManagedObjects call.
---
 ell/dbus-client.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/ell/dbus-client.c b/ell/dbus-client.c
index e29c6fae3288..61f068fe66b1 100644
--- a/ell/dbus-client.c
+++ b/ell/dbus-client.c
@@ -594,17 +594,18 @@ LIB_EXPORT struct l_dbus_client *l_dbus_client_new(struct l_dbus *dbus,
 
 	client->dbus = dbus;
 
+	client->service = l_strdup(service);
 	client->watch = l_dbus_add_service_watch(dbus, service,
 						service_appeared_callback,
 						service_disappeared_callback,
 						client, NULL);
 
 	if (!client->watch) {
+		l_free(client->service);
 		l_free(client);
 		return NULL;
 	}
 
-	client->service = l_strdup(service);
 	client->proxies = l_queue_new();
 
 	return client;
-- 
2.43.0